reload.c revision 107605
118334Speter/* Search an insn for pseudo regs that must be in hard regs and are not. 290075Sobrien Copyright (C) 1987, 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 3169689Skan 1999, 2000, 2001, 2002 Free Software Foundation, Inc. 4169689Skan 518334SpeterThis file is part of GCC. 690075Sobrien 718334SpeterGCC is free software; you can redistribute it and/or modify it under 890075Sobrienthe terms of the GNU General Public License as published by the Free 990075SobrienSoftware Foundation; either version 2, or (at your option) any later 1090075Sobrienversion. 1190075Sobrien 1218334SpeterGCC is distributed in the hope that it will be useful, but WITHOUT ANY 1390075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or 1490075SobrienFITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1590075Sobrienfor more details. 1690075Sobrien 1718334SpeterYou should have received a copy of the GNU General Public License 1818334Speteralong with GCC; see the file COPYING. If not, write to the Free 1990075SobrienSoftware Foundation, 59 Temple Place - Suite 330, Boston, MA 20169689Skan02111-1307, USA. */ 21169689Skan 2218334Speter/* This file contains subroutines used only from the file reload1.c. 2318334Speter It knows how to scan one insn for operands and values 2418334Speter that need to be copied into registers to make valid code. 2518334Speter It also finds other operands and values which are valid 2618334Speter but for which equivalent values in registers exist and 2718334Speter ought to be used instead. 2818334Speter 2918334Speter Before processing the first insn of the function, call `init_reload'. 3018334Speter 3150397Sobrien To scan an insn, call `find_reloads'. This does two things: 3250397Sobrien 1. sets up tables describing which values must be reloaded 33132718Skan for this insn, and what kind of hard regs they must be reloaded into; 34132718Skan 2. optionally record the locations where those values appear in 3518334Speter the data, so they can be replaced properly later. 3618334Speter This is done only if the second arg to `find_reloads' is nonzero. 3718334Speter 3818334Speter The third arg to `find_reloads' specifies the number of levels 3918334Speter of indirect addressing supported by the machine. If it is zero, 4018334Speter indirect addressing is not valid. If it is one, (MEM (REG n)) 4118334Speter is valid even if (REG n) did not get a hard register; if it is two, 42117395Skan (MEM (MEM (REG n))) is also valid even if (REG n) did not get a 4390075Sobrien hard register, and similarly for higher values. 4450397Sobrien 4590075Sobrien Then you must choose the hard regs to reload those pseudo regs into, 4618334Speter and generate appropriate load insns before this insn and perhaps 4790075Sobrien also store insns after this insn. Set up the array `reload_reg_rtx' 4890075Sobrien to contain the REG rtx's for the registers you used. In some 4990075Sobrien cases `find_reloads' will return a nonzero value in `reload_reg_rtx' 5090075Sobrien for certain reloads. Then that tells you which register to use, 5190075Sobrien so you do not need to allocate one. But you still do need to add extra 52169689Skan instructions to copy the value into and out of that register. 53132718Skan 54169689Skan Finally you must call `subst_reloads' to substitute the reload reg rtx's 55169689Skan into the locations already recorded. 5618334Speter 5718334SpeterNOTE SIDE EFFECTS: 5890075Sobrien 5990075Sobrien find_reloads can alter the operands of the instruction it is called on. 6018334Speter 6118334Speter 1. Two operands of any sort may be interchanged, if they are in a 62169689Skan commutative instruction. 63169689Skan This happens only if find_reloads thinks the instruction will compile 64169689Skan better that way. 6518334Speter 6690075Sobrien 2. Pseudo-registers that are equivalent to constants are replaced 6790075Sobrien with those constants if they are not in hard registers. 6818334Speter 6990075Sobrien1 happens every time find_reloads is called. 70117395Skan2 happens only when REPLACE is 1, which is only when 71169689Skanactually doing the reloads, not when just counting them. 7290075Sobrien 73117395SkanUsing a reload register for several reloads in one insn: 7490075Sobrien 75169689SkanWhen an insn has reloads, it is considered as having three parts: 76169689Skanthe input reloads, the insn itself after reloading, and the output reloads. 7790075SobrienReloads of values used in memory addresses are often needed for only one part. 78132718Skan 79132718SkanWhen this is so, reload_when_needed records which part needs the reload. 80132718SkanTwo reloads for different parts of the insn can share the same reload 8190075Sobrienregister. 8290075Sobrien 83132718SkanWhen a reload is used for addresses in multiple parts, or when it is 8490075Sobrienan ordinary operand, it is classified as RELOAD_OTHER, and cannot share 8518334Spetera register with any other reload. */ 8618334Speter 8718334Speter#define REG_OK_STRICT 88132718Skan 8918334Speter#include "config.h" 9018334Speter#include "system.h" 9118334Speter#include "rtl.h" 9218334Speter#include "tm_p.h" 9318334Speter#include "insn-config.h" 9418334Speter#include "expr.h" 9518334Speter#include "optabs.h" 9618334Speter#include "recog.h" 9718334Speter#include "reload.h" 9818334Speter#include "regs.h" 9918334Speter#include "hard-reg-set.h" 10018334Speter#include "flags.h" 10118334Speter#include "real.h" 102169689Skan#include "output.h" 103169689Skan#include "function.h" 10418334Speter#include "toplev.h" 105169689Skan 106169689Skan#ifndef REGISTER_MOVE_COST 107169689Skan#define REGISTER_MOVE_COST(m, x, y) 2 108169689Skan#endif 109169689Skan 11090075Sobrien#ifndef REGNO_MODE_OK_FOR_BASE_P 11118334Speter#define REGNO_MODE_OK_FOR_BASE_P(REGNO, MODE) REGNO_OK_FOR_BASE_P (REGNO) 112132718Skan#endif 113132718Skan 114132718Skan#ifndef REG_MODE_OK_FOR_BASE_P 115132718Skan#define REG_MODE_OK_FOR_BASE_P(REGNO, MODE) REG_OK_FOR_BASE_P (REGNO) 116132718Skan#endif 117132718Skan 118132718Skan/* All reloads of the current insn are recorded here. See reload.h for 119132718Skan comments. */ 120132718Skanint n_reloads; 121132718Skanstruct reload rld[MAX_RELOADS]; 122132718Skan 123132718Skan/* All the "earlyclobber" operands of the current insn 124132718Skan are recorded here. */ 125132718Skanint n_earlyclobbers; 126132718Skanrtx reload_earlyclobbers[MAX_RECOG_OPERANDS]; 127132718Skan 128132718Skanint reload_n_operands; 129169689Skan 13050397Sobrien/* Replacing reloads. 131132718Skan 132132718Skan If `replace_reloads' is nonzero, then as each reload is recorded 13350397Sobrien an entry is made for it in the table `replacements'. 13450397Sobrien Then later `subst_reloads' can look through that table and 135132718Skan perform all the replacements needed. */ 136132718Skan 137132718Skan/* Nonzero means record the places to replace. */ 13850397Sobrienstatic int replace_reloads; 13950397Sobrien 140132718Skan/* Each replacement is recorded with a structure like this. */ 141169689Skanstruct replacement 14218334Speter{ 143169689Skan rtx *where; /* Location to store in */ 144169689Skan rtx *subreg_loc; /* Location of SUBREG if WHERE is inside 145169689Skan a SUBREG; 0 otherwise. */ 146169689Skan int what; /* which reload this is for */ 147169689Skan enum machine_mode mode; /* mode it must have */ 148169689Skan}; 149169689Skan 150169689Skanstatic struct replacement replacements[MAX_RECOG_OPERANDS * ((MAX_REGS_PER_ADDRESS * 2) + 1)]; 151169689Skan 15218334Speter/* Number of replacements currently recorded. */ 153169689Skanstatic int n_replacements; 154169689Skan 155169689Skan/* Used to track what is modified by an operand. */ 156169689Skanstruct decomposition 157169689Skan{ 158169689Skan int reg_flag; /* Nonzero if referencing a register. */ 159169689Skan int safe; /* Nonzero if this can't conflict with anything. */ 160169689Skan rtx base; /* Base address for MEM. */ 161169689Skan HOST_WIDE_INT start; /* Starting offset or register number. */ 162169689Skan HOST_WIDE_INT end; /* Ending offset or register number. */ 163169689Skan}; 164169689Skan 165169689Skan#ifdef SECONDARY_MEMORY_NEEDED 166169689Skan 167169689Skan/* Save MEMs needed to copy from one class of registers to another. One MEM 168169689Skan is used per mode, but normally only one or two modes are ever used. 169169689Skan 170169689Skan We keep two versions, before and after register elimination. The one 171169689Skan after register elimination is record separately for each operand. This 172169689Skan is done in case the address is not valid to be sure that we separately 173169689Skan reload each. */ 174169689Skan 175169689Skanstatic rtx secondary_memlocs[NUM_MACHINE_MODES]; 176169689Skanstatic rtx secondary_memlocs_elim[NUM_MACHINE_MODES][MAX_RECOG_OPERANDS]; 177169689Skan#endif 178169689Skan 179169689Skan/* The instruction we are doing reloads for; 180169689Skan so we can test whether a register dies in it. */ 181169689Skanstatic rtx this_insn; 182169689Skan 183117395Skan/* Nonzero if this instruction is a user-specified asm with operands. */ 18490075Sobrienstatic int this_insn_is_asm; 18518334Speter 18618334Speter/* If hard_regs_live_known is nonzero, 18718334Speter we can tell which hard regs are currently live, 18890075Sobrien at least enough to succeed in choosing dummy reloads. */ 18918334Speterstatic int hard_regs_live_known; 190169689Skan 191169689Skan/* Indexed by hard reg number, 19218334Speter element is nonnegative if hard reg has been spilled. 193169689Skan This vector is passed to `find_reloads' as an argument 194169689Skan and is not changed here. */ 19590075Sobrienstatic short *static_reload_reg_p; 196169689Skan 197169689Skan/* Set to 1 in subst_reg_equivs if it changes anything. */ 19890075Sobrienstatic int subst_reg_equivs_changed; 199169689Skan 200169689Skan/* On return from push_reload, holds the reload-number for the OUT 20190075Sobrien operand, which can be different for that from the input operand. */ 202169689Skanstatic int output_reloadnum; 20318334Speter 204169689Skan /* Compare two RTX's. */ 205169689Skan#define MATCHES(x, y) \ 206169689Skan (x == y || (x != 0 && (GET_CODE (x) == REG \ 207169689Skan ? GET_CODE (y) == REG && REGNO (x) == REGNO (y) \ 208169689Skan : rtx_equal_p (x, y) && ! side_effects_p (x)))) 20918334Speter 210169689Skan /* Indicates if two reloads purposes are for similar enough things that we 21118334Speter can merge their reloads. */ 21218334Speter#define MERGABLE_RELOADS(when1, when2, op1, op2) \ 213169689Skan ((when1) == RELOAD_OTHER || (when2) == RELOAD_OTHER \ 214169689Skan || ((when1) == (when2) && (op1) == (op2)) \ 21518334Speter || ((when1) == RELOAD_FOR_INPUT && (when2) == RELOAD_FOR_INPUT) \ 216169689Skan || ((when1) == RELOAD_FOR_OPERAND_ADDRESS \ 217169689Skan && (when2) == RELOAD_FOR_OPERAND_ADDRESS) \ 21818334Speter || ((when1) == RELOAD_FOR_OTHER_ADDRESS \ 219117395Skan && (when2) == RELOAD_FOR_OTHER_ADDRESS)) 220169689Skan 22118334Speter /* Nonzero if these two reload purposes produce RELOAD_OTHER when merged. */ 222169689Skan#define MERGE_TO_OTHER(when1, when2, op1, op2) \ 223169689Skan ((when1) != (when2) \ 22418334Speter || ! ((op1) == (op2) \ 225169689Skan || (when1) == RELOAD_FOR_INPUT \ 226169689Skan || (when1) == RELOAD_FOR_OPERAND_ADDRESS \ 227169689Skan || (when1) == RELOAD_FOR_OTHER_ADDRESS)) 22818334Speter 22918334Speter /* If we are going to reload an address, compute the reload type to 230169689Skan use. */ 23118334Speter#define ADDR_TYPE(type) \ 232169689Skan ((type) == RELOAD_FOR_INPUT_ADDRESS \ 233169689Skan ? RELOAD_FOR_INPADDR_ADDRESS \ 23418334Speter : ((type) == RELOAD_FOR_OUTPUT_ADDRESS \ 235169689Skan ? RELOAD_FOR_OUTADDR_ADDRESS \ 236169689Skan : (type))) 237169689Skan 238169689Skan#ifdef HAVE_SECONDARY_RELOADS 23918334Speterstatic int push_secondary_reload PARAMS ((int, rtx, int, int, enum reg_class, 24018334Speter enum machine_mode, enum reload_type, 241169689Skan enum insn_code *)); 242169689Skan#endif 24350397Sobrienstatic enum reg_class find_valid_class PARAMS ((enum machine_mode, int, 244169689Skan unsigned int)); 245169689Skanstatic int reload_inner_reg_of_subreg PARAMS ((rtx, enum machine_mode, int)); 24650397Sobrienstatic void push_replacement PARAMS ((rtx *, int, enum machine_mode)); 24750397Sobrienstatic void combine_reloads PARAMS ((void)); 248169689Skanstatic int find_reusable_reload PARAMS ((rtx *, rtx, enum reg_class, 24990075Sobrien enum reload_type, int, int)); 250169689Skanstatic rtx find_dummy_reload PARAMS ((rtx, rtx, rtx *, rtx *, 251169689Skan enum machine_mode, enum machine_mode, 252169689Skan enum reg_class, int, int)); 25390075Sobrienstatic int hard_reg_set_here_p PARAMS ((unsigned int, unsigned int, rtx)); 254169689Skanstatic struct decomposition decompose PARAMS ((rtx)); 25590075Sobrienstatic int immune_p PARAMS ((rtx, rtx, struct decomposition)); 256169689Skanstatic int alternative_allows_memconst PARAMS ((const char *, int)); 257169689Skanstatic rtx find_reloads_toplev PARAMS ((rtx, int, enum reload_type, int, 258169689Skan int, rtx, int *)); 259169689Skanstatic rtx make_memloc PARAMS ((rtx, int)); 260169689Skanstatic int find_reloads_address PARAMS ((enum machine_mode, rtx *, rtx, rtx *, 26190075Sobrien int, enum reload_type, int, rtx)); 262169689Skanstatic rtx subst_reg_equivs PARAMS ((rtx, rtx)); 263169689Skanstatic rtx subst_indexed_address PARAMS ((rtx)); 26490075Sobrienstatic void update_auto_inc_notes PARAMS ((rtx, int, int)); 26590075Sobrienstatic int find_reloads_address_1 PARAMS ((enum machine_mode, rtx, int, rtx *, 266169689Skan int, enum reload_type,int, rtx)); 26790075Sobrienstatic void find_reloads_address_part PARAMS ((rtx, rtx *, enum reg_class, 268169689Skan enum machine_mode, int, 269169689Skan enum reload_type, int)); 27090075Sobrienstatic rtx find_reloads_subreg_address PARAMS ((rtx, int, int, 271169689Skan enum reload_type, int, rtx)); 27290075Sobrienstatic void copy_replacements_1 PARAMS ((rtx *, rtx *, int)); 273169689Skanstatic int find_inc_amount PARAMS ((rtx, rtx)); 274169689Skan 275169689Skan#ifdef HAVE_SECONDARY_RELOADS 27690075Sobrien 277169689Skan/* Determine if any secondary reloads are needed for loading (if IN_P is 27890075Sobrien non-zero) or storing (if IN_P is zero) X to or from a reload register of 27990075Sobrien register class RELOAD_CLASS in mode RELOAD_MODE. If secondary reloads 280169689Skan are needed, push them. 281169689Skan 28290075Sobrien Return the reload number of the secondary reload we made, or -1 if 283169689Skan we didn't need one. *PICODE is set to the insn_code to use if we do 284169689Skan need a secondary reload. */ 28590075Sobrien 286169689Skanstatic int 28790075Sobrienpush_secondary_reload (in_p, x, opnum, optional, reload_class, reload_mode, 288169689Skan type, picode) 289169689Skan int in_p; 290169689Skan rtx x; 291169689Skan int opnum; 292169689Skan int optional; 29390075Sobrien enum reg_class reload_class; 294169689Skan enum machine_mode reload_mode; 295169689Skan enum reload_type type; 296169689Skan enum insn_code *picode; 297169689Skan{ 298169689Skan enum reg_class class = NO_REGS; 29990075Sobrien enum machine_mode mode = reload_mode; 300117395Skan enum insn_code icode = CODE_FOR_nothing; 30190075Sobrien enum reg_class t_class = NO_REGS; 302169689Skan enum machine_mode t_mode = VOIDmode; 303169689Skan enum insn_code t_icode = CODE_FOR_nothing; 304169689Skan enum reload_type secondary_type; 305169689Skan int s_reload, t_reload = -1; 306169689Skan 307169689Skan if (type == RELOAD_FOR_INPUT_ADDRESS 308169689Skan || type == RELOAD_FOR_OUTPUT_ADDRESS 309169689Skan || type == RELOAD_FOR_INPADDR_ADDRESS 310169689Skan || type == RELOAD_FOR_OUTADDR_ADDRESS) 311169689Skan secondary_type = type; 31290075Sobrien else 313169689Skan secondary_type = in_p ? RELOAD_FOR_INPUT_ADDRESS : RELOAD_FOR_OUTPUT_ADDRESS; 31490075Sobrien 31590075Sobrien *picode = CODE_FOR_nothing; 316169689Skan 317169689Skan /* If X is a paradoxical SUBREG, use the inner value to determine both the 31890075Sobrien mode and object being reloaded. */ 319169689Skan if (GET_CODE (x) == SUBREG 320169689Skan && (GET_MODE_SIZE (GET_MODE (x)) 321169689Skan > GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))) 322169689Skan { 323169689Skan x = SUBREG_REG (x); 32490075Sobrien reload_mode = GET_MODE (x); 325169689Skan } 326169689Skan 327169689Skan /* If X is a pseudo-register that has an equivalent MEM (actually, if it 328169689Skan is still a pseudo-register by now, it *must* have an equivalent MEM 329169689Skan but we don't want to assume that), use that equivalent when seeing if 330169689Skan a secondary reload is needed since whether or not a reload is needed 33190075Sobrien might be sensitive to the form of the MEM. */ 332169689Skan 333169689Skan if (GET_CODE (x) == REG && REGNO (x) >= FIRST_PSEUDO_REGISTER 33490075Sobrien && reg_equiv_mem[REGNO (x)] != 0) 335169689Skan x = reg_equiv_mem[REGNO (x)]; 336169689Skan 33790075Sobrien#ifdef SECONDARY_INPUT_RELOAD_CLASS 338169689Skan if (in_p) 339169689Skan class = SECONDARY_INPUT_RELOAD_CLASS (reload_class, reload_mode, x); 340169689Skan#endif 341169689Skan 34290075Sobrien#ifdef SECONDARY_OUTPUT_RELOAD_CLASS 343169689Skan if (! in_p) 344169689Skan class = SECONDARY_OUTPUT_RELOAD_CLASS (reload_class, reload_mode, x); 345169689Skan#endif 346169689Skan 34790075Sobrien /* If we don't need any secondary registers, done. */ 348169689Skan if (class == NO_REGS) 349169689Skan return -1; 35090075Sobrien 351169689Skan /* Get a possible insn to use. If the predicate doesn't accept X, don't 352169689Skan use the insn. */ 353169689Skan 354169689Skan icode = (in_p ? reload_in_optab[(int) reload_mode] 355169689Skan : reload_out_optab[(int) reload_mode]); 356169689Skan 357169689Skan if (icode != CODE_FOR_nothing 358169689Skan && insn_data[(int) icode].operand[in_p].predicate 359169689Skan && (! (insn_data[(int) icode].operand[in_p].predicate) (x, reload_mode))) 360169689Skan icode = CODE_FOR_nothing; 361169689Skan 362169689Skan /* If we will be using an insn, see if it can directly handle the reload 363169689Skan register we will be using. If it can, the secondary reload is for a 364169689Skan scratch register. If it can't, we will use the secondary reload for 365169689Skan an intermediate register and require a tertiary reload for the scratch 366169689Skan register. */ 367169689Skan 368169689Skan if (icode != CODE_FOR_nothing) 369169689Skan { 370169689Skan /* If IN_P is non-zero, the reload register will be the output in 371169689Skan operand 0. If IN_P is zero, the reload register will be the input 372169689Skan in operand 1. Outputs should have an initial "=", which we must 373169689Skan skip. */ 374169689Skan 375169689Skan enum reg_class insn_class; 376169689Skan 377169689Skan if (insn_data[(int) icode].operand[!in_p].constraint[0] == 0) 37890075Sobrien insn_class = ALL_REGS; 37990075Sobrien else 380169689Skan { 381169689Skan char insn_letter 382169689Skan = insn_data[(int) icode].operand[!in_p].constraint[in_p]; 383169689Skan insn_class 384169689Skan = (insn_letter == 'r' ? GENERAL_REGS 385169689Skan : REG_CLASS_FROM_LETTER ((unsigned char) insn_letter)); 38690075Sobrien 387169689Skan if (insn_class == NO_REGS) 388169689Skan abort (); 389169689Skan if (in_p 390169689Skan && insn_data[(int) icode].operand[!in_p].constraint[0] != '=') 391169689Skan abort (); 392169689Skan } 39390075Sobrien 394169689Skan /* The scratch register's constraint must start with "=&". */ 395169689Skan if (insn_data[(int) icode].operand[2].constraint[0] != '=' 39690075Sobrien || insn_data[(int) icode].operand[2].constraint[1] != '&') 397169689Skan abort (); 39890075Sobrien 399169689Skan if (reg_class_subset_p (reload_class, insn_class)) 400169689Skan mode = insn_data[(int) icode].operand[2].mode; 40190075Sobrien else 402169689Skan { 403169689Skan char t_letter = insn_data[(int) icode].operand[2].constraint[2]; 40490075Sobrien class = insn_class; 40590075Sobrien t_mode = insn_data[(int) icode].operand[2].mode; 406169689Skan t_class = (t_letter == 'r' ? GENERAL_REGS 40718334Speter : REG_CLASS_FROM_LETTER ((unsigned char) t_letter)); 408169689Skan t_icode = icode; 409169689Skan icode = CODE_FOR_nothing; 41018334Speter } 411169689Skan } 412169689Skan 413169689Skan /* This case isn't valid, so fail. Reload is allowed to use the same 414169689Skan register for RELOAD_FOR_INPUT_ADDRESS and RELOAD_FOR_INPUT reloads, but 415169689Skan in the case of a secondary register, we actually need two different 416169689Skan registers for correct code. We fail here to prevent the possibility of 417169689Skan silently generating incorrect code later. 418169689Skan 419169689Skan The convention is that secondary input reloads are valid only if the 420169689Skan secondary_class is different from class. If you have such a case, you 421169689Skan can not use secondary reloads, you must work around the problem some 422169689Skan other way. 423169689Skan 424169689Skan Allow this when a reload_in/out pattern is being used. I.e. assume 425169689Skan that the generated code handles this case. */ 426169689Skan 427169689Skan if (in_p && class == reload_class && icode == CODE_FOR_nothing 428169689Skan && t_icode == CODE_FOR_nothing) 429169689Skan abort (); 430169689Skan 431169689Skan /* If we need a tertiary reload, see if we have one we can reuse or else 432169689Skan make a new one. */ 433169689Skan 434169689Skan if (t_class != NO_REGS) 435169689Skan { 436169689Skan for (t_reload = 0; t_reload < n_reloads; t_reload++) 437169689Skan if (rld[t_reload].secondary_p 438169689Skan && (reg_class_subset_p (t_class, rld[t_reload].class) 439169689Skan || reg_class_subset_p (rld[t_reload].class, t_class)) 440169689Skan && ((in_p && rld[t_reload].inmode == t_mode) 441169689Skan || (! in_p && rld[t_reload].outmode == t_mode)) 442169689Skan && ((in_p && (rld[t_reload].secondary_in_icode 443169689Skan == CODE_FOR_nothing)) 444169689Skan || (! in_p &&(rld[t_reload].secondary_out_icode 445169689Skan == CODE_FOR_nothing))) 446169689Skan && (reg_class_size[(int) t_class] == 1 || SMALL_REGISTER_CLASSES) 447169689Skan && MERGABLE_RELOADS (secondary_type, 448169689Skan rld[t_reload].when_needed, 449169689Skan opnum, rld[t_reload].opnum)) 450169689Skan { 451169689Skan if (in_p) 452169689Skan rld[t_reload].inmode = t_mode; 45390075Sobrien if (! in_p) 45490075Sobrien rld[t_reload].outmode = t_mode; 455169689Skan 45618334Speter if (reg_class_subset_p (t_class, rld[t_reload].class)) 45718334Speter rld[t_reload].class = t_class; 45818334Speter 459169689Skan rld[t_reload].opnum = MIN (rld[t_reload].opnum, opnum); 46090075Sobrien rld[t_reload].optional &= optional; 461169689Skan rld[t_reload].secondary_p = 1; 46218334Speter if (MERGE_TO_OTHER (secondary_type, rld[t_reload].when_needed, 46318334Speter opnum, rld[t_reload].opnum)) 46490075Sobrien rld[t_reload].when_needed = RELOAD_OTHER; 46550397Sobrien } 466132718Skan 467132718Skan if (t_reload == n_reloads) 468132718Skan { 46990075Sobrien /* We need to make a new tertiary reload for this register class. */ 47090075Sobrien rld[t_reload].in = rld[t_reload].out = 0; 471117395Skan rld[t_reload].class = t_class; 472102780Skan rld[t_reload].inmode = in_p ? t_mode : VOIDmode; 473117395Skan rld[t_reload].outmode = ! in_p ? t_mode : VOIDmode; 474169689Skan rld[t_reload].reg_rtx = 0; 47590075Sobrien rld[t_reload].optional = optional; 47690075Sobrien rld[t_reload].inc = 0; 47750397Sobrien /* Maybe we could combine these, but it seems too tricky. */ 47850397Sobrien rld[t_reload].nocombine = 1; 47950397Sobrien rld[t_reload].in_reg = 0; 48050397Sobrien rld[t_reload].out_reg = 0; 48150397Sobrien rld[t_reload].opnum = opnum; 48250397Sobrien rld[t_reload].when_needed = secondary_type; 48350397Sobrien rld[t_reload].secondary_in_reload = -1; 48450397Sobrien rld[t_reload].secondary_out_reload = -1; 48550397Sobrien rld[t_reload].secondary_in_icode = CODE_FOR_nothing; 48650397Sobrien rld[t_reload].secondary_out_icode = CODE_FOR_nothing; 487132718Skan rld[t_reload].secondary_p = 1; 488132718Skan 489132718Skan n_reloads++; 490132718Skan } 49150397Sobrien } 492169689Skan 493169689Skan /* See if we can reuse an existing secondary reload. */ 49450397Sobrien for (s_reload = 0; s_reload < n_reloads; s_reload++) 49550397Sobrien if (rld[s_reload].secondary_p 49650397Sobrien && (reg_class_subset_p (class, rld[s_reload].class) 49750397Sobrien || reg_class_subset_p (rld[s_reload].class, class)) 49850397Sobrien && ((in_p && rld[s_reload].inmode == mode) 49950397Sobrien || (! in_p && rld[s_reload].outmode == mode)) 50050397Sobrien && ((in_p && rld[s_reload].secondary_in_reload == t_reload) 501102780Skan || (! in_p && rld[s_reload].secondary_out_reload == t_reload)) 50250397Sobrien && ((in_p && rld[s_reload].secondary_in_icode == t_icode) 50350397Sobrien || (! in_p && rld[s_reload].secondary_out_icode == t_icode)) 50450397Sobrien && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES) 50550397Sobrien && MERGABLE_RELOADS (secondary_type, rld[s_reload].when_needed, 50650397Sobrien opnum, rld[s_reload].opnum)) 50750397Sobrien { 50850397Sobrien if (in_p) 50950397Sobrien rld[s_reload].inmode = mode; 51050397Sobrien if (! in_p) 51150397Sobrien rld[s_reload].outmode = mode; 51250397Sobrien 51350397Sobrien if (reg_class_subset_p (class, rld[s_reload].class)) 514132718Skan rld[s_reload].class = class; 515132718Skan 516132718Skan rld[s_reload].opnum = MIN (rld[s_reload].opnum, opnum); 51750397Sobrien rld[s_reload].optional &= optional; 518169689Skan rld[s_reload].secondary_p = 1; 51950397Sobrien if (MERGE_TO_OTHER (secondary_type, rld[s_reload].when_needed, 52050397Sobrien opnum, rld[s_reload].opnum)) 52150397Sobrien rld[s_reload].when_needed = RELOAD_OTHER; 52250397Sobrien } 52350397Sobrien 52450397Sobrien if (s_reload == n_reloads) 52550397Sobrien { 52650397Sobrien#ifdef SECONDARY_MEMORY_NEEDED 52750397Sobrien /* If we need a memory location to copy between the two reload regs, 52850397Sobrien set it up now. Note that we do the input case before making 52950397Sobrien the reload and the output case after. This is due to the 53050397Sobrien way reloads are output. */ 53150397Sobrien 53250397Sobrien if (in_p && icode == CODE_FOR_nothing 53350397Sobrien && SECONDARY_MEMORY_NEEDED (class, reload_class, mode)) 534169689Skan { 535169689Skan get_secondary_mem (x, reload_mode, opnum, type); 536169689Skan 53718334Speter /* We may have just added new reloads. Make sure we add 538169689Skan the new reload at the end. */ 539169689Skan s_reload = n_reloads; 540169689Skan } 541169689Skan#endif 542169689Skan 543169689Skan /* We need to make a new secondary reload for this register class. */ 544169689Skan rld[s_reload].in = rld[s_reload].out = 0; 545169689Skan rld[s_reload].class = class; 546169689Skan 547169689Skan rld[s_reload].inmode = in_p ? mode : VOIDmode; 548169689Skan rld[s_reload].outmode = ! in_p ? mode : VOIDmode; 54918334Speter rld[s_reload].reg_rtx = 0; 550169689Skan rld[s_reload].optional = optional; 551169689Skan rld[s_reload].inc = 0; 552169689Skan /* Maybe we could combine these, but it seems too tricky. */ 553169689Skan rld[s_reload].nocombine = 1; 554169689Skan rld[s_reload].in_reg = 0; 555169689Skan rld[s_reload].out_reg = 0; 556132718Skan rld[s_reload].opnum = opnum; 55718334Speter rld[s_reload].when_needed = secondary_type; 558169689Skan rld[s_reload].secondary_in_reload = in_p ? t_reload : -1; 559169689Skan rld[s_reload].secondary_out_reload = ! in_p ? t_reload : -1; 560169689Skan rld[s_reload].secondary_in_icode = in_p ? t_icode : CODE_FOR_nothing; 561169689Skan rld[s_reload].secondary_out_icode 562169689Skan = ! in_p ? t_icode : CODE_FOR_nothing; 563169689Skan rld[s_reload].secondary_p = 1; 56418334Speter 56518334Speter n_reloads++; 566169689Skan 567169689Skan#ifdef SECONDARY_MEMORY_NEEDED 56850397Sobrien if (! in_p && icode == CODE_FOR_nothing 569169689Skan && SECONDARY_MEMORY_NEEDED (reload_class, class, mode)) 570169689Skan get_secondary_mem (x, mode, opnum, type); 571169689Skan#endif 572169689Skan } 57318334Speter 57450397Sobrien *picode = icode; 575169689Skan return s_reload; 576169689Skan} 57750397Sobrien#endif /* HAVE_SECONDARY_RELOADS */ 578169689Skan 579169689Skan#ifdef SECONDARY_MEMORY_NEEDED 580169689Skan 581169689Skan/* Return a memory location that will be used to copy X in mode MODE. 582169689Skan If we haven't already made a location for this mode in this insn, 583169689Skan call find_reloads_address on the location being returned. */ 58450397Sobrien 585169689Skanrtx 586169689Skanget_secondary_mem (x, mode, opnum, type) 587169689Skan rtx x ATTRIBUTE_UNUSED; 588169689Skan enum machine_mode mode; 589169689Skan int opnum; 590169689Skan enum reload_type type; 591169689Skan{ 592169689Skan rtx loc; 59350397Sobrien int mem_valid; 59450397Sobrien 595169689Skan /* By default, if MODE is narrower than a word, widen it to a word. 59690075Sobrien This is required because most machines that require these memory 597169689Skan locations do not support short load and stores from all registers 598169689Skan (e.g., FP registers). */ 599169689Skan 600169689Skan#ifdef SECONDARY_MEMORY_NEEDED_MODE 601169689Skan mode = SECONDARY_MEMORY_NEEDED_MODE (mode); 602169689Skan#else 603169689Skan if (GET_MODE_BITSIZE (mode) < BITS_PER_WORD && INTEGRAL_MODE_P (mode)) 604169689Skan mode = mode_for_size (BITS_PER_WORD, GET_MODE_CLASS (mode), 0); 605169689Skan#endif 606169689Skan 607169689Skan /* If we already have made a MEM for this operand in MODE, return it. */ 608169689Skan if (secondary_memlocs_elim[(int) mode][opnum] != 0) 609169689Skan return secondary_memlocs_elim[(int) mode][opnum]; 610169689Skan 611169689Skan /* If this is the first time we've tried to get a MEM for this mode, 612169689Skan allocate a new one. `something_changed' in reload will get set 613169689Skan by noticing that the frame size has changed. */ 614169689Skan 615169689Skan if (secondary_memlocs[(int) mode] == 0) 616169689Skan { 617169689Skan#ifdef SECONDARY_MEMORY_NEEDED_RTX 618169689Skan secondary_memlocs[(int) mode] = SECONDARY_MEMORY_NEEDED_RTX (mode); 619169689Skan#else 620169689Skan secondary_memlocs[(int) mode] 621169689Skan = assign_stack_local (mode, GET_MODE_SIZE (mode), 0); 622169689Skan#endif 623169689Skan } 624169689Skan 625169689Skan /* Get a version of the address doing any eliminations needed. If that 626169689Skan didn't give us a new MEM, make a new one if it isn't valid. */ 627169689Skan 628169689Skan loc = eliminate_regs (secondary_memlocs[(int) mode], VOIDmode, NULL_RTX); 629169689Skan mem_valid = strict_memory_address_p (mode, XEXP (loc, 0)); 630169689Skan 631169689Skan if (! mem_valid && loc == secondary_memlocs[(int) mode]) 632169689Skan loc = copy_rtx (loc); 633169689Skan 634169689Skan /* The only time the call below will do anything is if the stack 635169689Skan offset is too large. In that case IND_LEVELS doesn't matter, so we 636169689Skan can just pass a zero. Adjust the type to be the address of the 637169689Skan corresponding object. If the address was valid, save the eliminated 638169689Skan address. If it wasn't valid, we need to make a reload each time, so 639169689Skan don't save it. */ 640169689Skan 641169689Skan if (! mem_valid) 642169689Skan { 643169689Skan type = (type == RELOAD_FOR_INPUT ? RELOAD_FOR_INPUT_ADDRESS 644169689Skan : type == RELOAD_FOR_OUTPUT ? RELOAD_FOR_OUTPUT_ADDRESS 645169689Skan : RELOAD_OTHER); 646169689Skan 647169689Skan find_reloads_address (mode, (rtx*) 0, XEXP (loc, 0), &XEXP (loc, 0), 648169689Skan opnum, type, 0, 0); 649169689Skan } 650169689Skan 651169689Skan secondary_memlocs_elim[(int) mode][opnum] = loc; 652169689Skan return loc; 653132718Skan} 654132718Skan 655132718Skan/* Clear any secondary memory locations we've made. */ 65618334Speter 657169689Skanvoid 658169689Skanclear_secondary_mem () 659132718Skan{ 66090075Sobrien memset ((char *) secondary_memlocs, 0, sizeof secondary_memlocs); 66190075Sobrien} 66290075Sobrien#endif /* SECONDARY_MEMORY_NEEDED */ 663169689Skan 664169689Skan/* Find the largest class for which every register number plus N is valid in 66518334Speter M1 (if in range) and is cheap to move into REGNO. 66690075Sobrien Abort if no such class exists. */ 66790075Sobrien 66890075Sobrienstatic enum reg_class 669169689Skanfind_valid_class (m1, n, dest_regno) 670169689Skan enum machine_mode m1 ATTRIBUTE_UNUSED; 67190075Sobrien int n; 67218334Speter unsigned int dest_regno; 67390075Sobrien{ 67490075Sobrien int best_cost = -1; 67590075Sobrien int class; 67690075Sobrien int regno; 67790075Sobrien enum reg_class best_class = NO_REGS; 67890075Sobrien enum reg_class dest_class = REGNO_REG_CLASS (dest_regno); 67990075Sobrien unsigned int best_size = 0; 68018334Speter int cost; 68190075Sobrien 68290075Sobrien for (class = 1; class < N_REG_CLASSES; class++) 68318334Speter { 68490075Sobrien int bad = 0; 68590075Sobrien for (regno = 0; regno < FIRST_PSEUDO_REGISTER && ! bad; regno++) 68690075Sobrien if (TEST_HARD_REG_BIT (reg_class_contents[class], regno) 68790075Sobrien && TEST_HARD_REG_BIT (reg_class_contents[class], regno + n) 688117395Skan && ! HARD_REGNO_MODE_OK (regno + n, m1)) 68990075Sobrien bad = 1; 69090075Sobrien 69190075Sobrien if (bad) 69290075Sobrien continue; 69390075Sobrien cost = REGISTER_MOVE_COST (m1, class, dest_class); 69490075Sobrien 69590075Sobrien if ((reg_class_size[class] > best_size 69690075Sobrien && (best_cost < 0 || best_cost >= cost)) 69790075Sobrien || best_cost > cost) 698169689Skan { 69990075Sobrien best_class = class; 70090075Sobrien best_size = reg_class_size[class]; 70118334Speter best_cost = REGISTER_MOVE_COST (m1, class, dest_class); 702132718Skan } 703169689Skan } 704117395Skan 70590075Sobrien if (best_size == 0) 706169689Skan abort (); 70790075Sobrien 708169689Skan return best_class; 709132718Skan} 710132718Skan 711132718Skan/* Return the number of a previously made reload that can be combined with 71290075Sobrien a new one, or n_reloads if none of the existing reloads can be used. 71390075Sobrien OUT, CLASS, TYPE and OPNUM are the same arguments as passed to 71490075Sobrien push_reload, they determine the kind of the new reload that we try to 715132718Skan combine. P_IN points to the corresponding value of IN, which can be 71690075Sobrien modified by this function. 71790075Sobrien DONT_SHARE is nonzero if we can't share any input-only reload for IN. */ 71890075Sobrien 71990075Sobrienstatic int 72090075Sobrienfind_reusable_reload (p_in, out, class, type, opnum, dont_share) 72190075Sobrien rtx *p_in, out; 72250397Sobrien enum reg_class class; 72390075Sobrien enum reload_type type; 72490075Sobrien int opnum, dont_share; 72590075Sobrien{ 72690075Sobrien rtx in = *p_in; 727169689Skan int i; 728117395Skan /* We can't merge two reloads if the output of either one is 729169689Skan earlyclobbered. */ 73018334Speter 73190075Sobrien if (earlyclobber_operand_p (out)) 73218334Speter return n_reloads; 73318334Speter 73452284Sobrien /* We can use an existing reload if the class is right 735132718Skan and at least one of IN and OUT is a match 73618334Speter and the other is at worst neutral. 73718334Speter (A zero compared against anything is neutral.) 73818334Speter 73918334Speter If SMALL_REGISTER_CLASSES, don't use existing reloads unless they are 74018334Speter for the same thing since that can cause us to need more reload registers 74118334Speter than we otherwise would. */ 74218334Speter 74318334Speter for (i = 0; i < n_reloads; i++) 74418334Speter if ((reg_class_subset_p (class, rld[i].class) 74518334Speter || reg_class_subset_p (rld[i].class, class)) 746169689Skan /* If the existing reload has a register, it must fit our class. */ 747169689Skan && (rld[i].reg_rtx == 0 748169689Skan || TEST_HARD_REG_BIT (reg_class_contents[(int) class], 749169689Skan true_regnum (rld[i].reg_rtx))) 750169689Skan && ((in != 0 && MATCHES (rld[i].in, in) && ! dont_share 751169689Skan && (out == 0 || rld[i].out == 0 || MATCHES (rld[i].out, out))) 752169689Skan || (out != 0 && MATCHES (rld[i].out, out) 753169689Skan && (in == 0 || rld[i].in == 0 || MATCHES (rld[i].in, in)))) 754169689Skan && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out)) 755169689Skan && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES) 756169689Skan && MERGABLE_RELOADS (type, rld[i].when_needed, opnum, rld[i].opnum)) 757169689Skan return i; 758169689Skan 75918334Speter /* Reloading a plain reg for input can match a reload to postincrement 76018334Speter that reg, since the postincrement's value is the right value. 76118334Speter Likewise, it can match a preincrement reload, since we regard 76218334Speter the preincrementation as happening before any ref in this insn 76318334Speter to that register. */ 76418334Speter for (i = 0; i < n_reloads; i++) 76518334Speter if ((reg_class_subset_p (class, rld[i].class) 76618334Speter || reg_class_subset_p (rld[i].class, class)) 76718334Speter /* If the existing reload has a register, it must fit our 768132718Skan class. */ 76918334Speter && (rld[i].reg_rtx == 0 77018334Speter || TEST_HARD_REG_BIT (reg_class_contents[(int) class], 77118334Speter true_regnum (rld[i].reg_rtx))) 77218334Speter && out == 0 && rld[i].out == 0 && rld[i].in != 0 77318334Speter && ((GET_CODE (in) == REG 77418334Speter && GET_RTX_CLASS (GET_CODE (rld[i].in)) == 'a' 77518334Speter && MATCHES (XEXP (rld[i].in, 0), in)) 77690075Sobrien || (GET_CODE (rld[i].in) == REG 77718334Speter && GET_RTX_CLASS (GET_CODE (in)) == 'a' 77818334Speter && MATCHES (XEXP (in, 0), rld[i].in))) 77990075Sobrien && (rld[i].out == 0 || ! earlyclobber_operand_p (rld[i].out)) 78018334Speter && (reg_class_size[(int) class] == 1 || SMALL_REGISTER_CLASSES) 78118334Speter && MERGABLE_RELOADS (type, rld[i].when_needed, 78218334Speter opnum, rld[i].opnum)) 78318334Speter { 78418334Speter /* Make sure reload_in ultimately has the increment, 78518334Speter not the plain register. */ 78618334Speter if (GET_CODE (in) == REG) 78718334Speter *p_in = rld[i].in; 78818334Speter return i; 78918334Speter } 79018334Speter return n_reloads; 79118334Speter} 79218334Speter 79318334Speter/* Return nonzero if X is a SUBREG which will require reloading of its 79418334Speter SUBREG_REG expression. */ 79518334Speter 79618334Speterstatic int 79790075Sobrienreload_inner_reg_of_subreg (x, mode, output) 79818334Speter rtx x; 79918334Speter enum machine_mode mode; 80090075Sobrien int output; 801169689Skan{ 802169689Skan rtx inner; 80318334Speter 80418334Speter /* Only SUBREGs are problematical. */ 80518334Speter if (GET_CODE (x) != SUBREG) 80618334Speter return 0; 80718334Speter 80818334Speter inner = SUBREG_REG (x); 80918334Speter 81018334Speter /* If INNER is a constant or PLUS, then INNER must be reloaded. */ 81118334Speter if (CONSTANT_P (inner) || GET_CODE (inner) == PLUS) 81218334Speter return 1; 81318334Speter 81418334Speter /* If INNER is not a hard register, then INNER will not need to 81518334Speter be reloaded. */ 81618334Speter if (GET_CODE (inner) != REG 81718334Speter || REGNO (inner) >= FIRST_PSEUDO_REGISTER) 81818334Speter return 0; 819169689Skan 820169689Skan /* If INNER is not ok for MODE, then INNER will need reloading. */ 821169689Skan if (! HARD_REGNO_MODE_OK (subreg_regno (x), mode)) 822169689Skan return 1; 823169689Skan 824169689Skan /* If the outer part is a word or smaller, INNER larger than a 825169689Skan word and the number of regs for INNER is not the same as the 826169689Skan number of words in INNER, then INNER will need reloading. */ 827169689Skan return (GET_MODE_SIZE (mode) <= UNITS_PER_WORD 828169689Skan && output 829169689Skan && GET_MODE_SIZE (GET_MODE (inner)) > UNITS_PER_WORD 830169689Skan && ((GET_MODE_SIZE (GET_MODE (inner)) / UNITS_PER_WORD) 831169689Skan != HARD_REGNO_NREGS (REGNO (inner), GET_MODE (inner)))); 832169689Skan} 833169689Skan 834169689Skan/* Record one reload that needs to be performed. 835169689Skan IN is an rtx saying where the data are to be found before this instruction. 836169689Skan OUT says where they must be stored after the instruction. 837169689Skan (IN is zero for data not read, and OUT is zero for data not written.) 838169689Skan INLOC and OUTLOC point to the places in the instructions where 839169689Skan IN and OUT were found. 840169689Skan If IN and OUT are both non-zero, it means the same register must be used 841169689Skan to reload both IN and OUT. 842169689Skan 843169689Skan CLASS is a register class required for the reloaded data. 844169689Skan INMODE is the machine mode that the instruction requires 845169689Skan for the reg that replaces IN and OUTMODE is likewise for OUT. 846169689Skan 847169689Skan If IN is zero, then OUT's location and mode should be passed as 848169689Skan INLOC and INMODE. 849169689Skan 850169689Skan STRICT_LOW is the 1 if there is a containing STRICT_LOW_PART rtx. 851169689Skan 852169689Skan OPTIONAL nonzero means this reload does not need to be performed: 853169689Skan it can be discarded if that is more convenient. 854169689Skan 855169689Skan OPNUM and TYPE say what the purpose of this reload is. 856169689Skan 857169689Skan The return value is the reload-number for this reload. 858169689Skan 859169689Skan If both IN and OUT are nonzero, in some rare cases we might 860169689Skan want to make two separate reloads. (Actually we never do this now.) 861169689Skan Therefore, the reload-number for OUT is stored in 862169689Skan output_reloadnum when we return; the return value applies to IN. 863169689Skan Usually (presently always), when IN and OUT are nonzero, 864169689Skan the two reload-numbers are equal, but the caller should be careful to 865169689Skan distinguish them. */ 866169689Skan 867169689Skanint 868169689Skanpush_reload (in, out, inloc, outloc, class, 869169689Skan inmode, outmode, strict_low, optional, opnum, type) 870169689Skan rtx in, out; 871169689Skan rtx *inloc, *outloc; 872169689Skan enum reg_class class; 873169689Skan enum machine_mode inmode, outmode; 874169689Skan int strict_low; 875169689Skan int optional; 876169689Skan int opnum; 877169689Skan enum reload_type type; 878169689Skan{ 879169689Skan int i; 880169689Skan int dont_share = 0; 881169689Skan int dont_remove_subreg = 0; 882169689Skan rtx *in_subreg_loc = 0, *out_subreg_loc = 0; 883169689Skan int secondary_in_reload = -1, secondary_out_reload = -1; 884169689Skan enum insn_code secondary_in_icode = CODE_FOR_nothing; 885169689Skan enum insn_code secondary_out_icode = CODE_FOR_nothing; 886169689Skan 887169689Skan /* INMODE and/or OUTMODE could be VOIDmode if no mode 888169689Skan has been specified for the operand. In that case, 889169689Skan use the operand's mode as the mode to reload. */ 890169689Skan if (inmode == VOIDmode && in != 0) 891169689Skan inmode = GET_MODE (in); 892169689Skan if (outmode == VOIDmode && out != 0) 893169689Skan outmode = GET_MODE (out); 894169689Skan 895169689Skan /* If IN is a pseudo register everywhere-equivalent to a constant, and 896169689Skan it is not in a hard register, reload straight from the constant, 897169689Skan since we want to get rid of such pseudo registers. 898169689Skan Often this is done earlier, but not always in find_reloads_address. */ 899169689Skan if (in != 0 && GET_CODE (in) == REG) 900169689Skan { 901169689Skan int regno = REGNO (in); 902169689Skan 903169689Skan if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0 904169689Skan && reg_equiv_constant[regno] != 0) 905169689Skan in = reg_equiv_constant[regno]; 906169689Skan } 907169689Skan 908169689Skan /* Likewise for OUT. Of course, OUT will never be equivalent to 909169689Skan an actual constant, but it might be equivalent to a memory location 910169689Skan (in the case of a parameter). */ 911169689Skan if (out != 0 && GET_CODE (out) == REG) 912169689Skan { 913169689Skan int regno = REGNO (out); 914169689Skan 915169689Skan if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0 916169689Skan && reg_equiv_constant[regno] != 0) 917169689Skan out = reg_equiv_constant[regno]; 918169689Skan } 919169689Skan 920169689Skan /* If we have a read-write operand with an address side-effect, 921169689Skan change either IN or OUT so the side-effect happens only once. */ 922169689Skan if (in != 0 && out != 0 && GET_CODE (in) == MEM && rtx_equal_p (in, out)) 923169689Skan switch (GET_CODE (XEXP (in, 0))) 924169689Skan { 925169689Skan case POST_INC: case POST_DEC: case POST_MODIFY: 926169689Skan in = replace_equiv_address_nv (in, XEXP (XEXP (in, 0), 0)); 927169689Skan break; 928169689Skan 929169689Skan case PRE_INC: case PRE_DEC: case PRE_MODIFY: 930169689Skan out = replace_equiv_address_nv (out, XEXP (XEXP (out, 0), 0)); 931169689Skan break; 932169689Skan 933169689Skan default: 934169689Skan break; 935169689Skan } 936169689Skan 937169689Skan /* If we are reloading a (SUBREG constant ...), really reload just the 938169689Skan inside expression in its own mode. Similarly for (SUBREG (PLUS ...)). 939169689Skan If we have (SUBREG:M1 (MEM:M2 ...) ...) (or an inner REG that is still 940169689Skan a pseudo and hence will become a MEM) with M1 wider than M2 and the 941169689Skan register is a pseudo, also reload the inside expression. 942169689Skan For machines that extend byte loads, do this for any SUBREG of a pseudo 943169689Skan where both M1 and M2 are a word or smaller, M1 is wider than M2, and 944169689Skan M2 is an integral mode that gets extended when loaded. 945169689Skan Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where 946169689Skan either M1 is not valid for R or M2 is wider than a word but we only 947169689Skan need one word to store an M2-sized quantity in R. 948169689Skan (However, if OUT is nonzero, we need to reload the reg *and* 949169689Skan the subreg, so do nothing here, and let following statement handle it.) 950169689Skan 951169689Skan Note that the case of (SUBREG (CONST_INT...)...) is handled elsewhere; 952169689Skan we can't handle it here because CONST_INT does not indicate a mode. 953169689Skan 954169689Skan Similarly, we must reload the inside expression if we have a 955169689Skan STRICT_LOW_PART (presumably, in == out in the cas). 956169689Skan 957169689Skan Also reload the inner expression if it does not require a secondary 958169689Skan reload but the SUBREG does. 959169689Skan 960169689Skan Finally, reload the inner expression if it is a register that is in 961169689Skan the class whose registers cannot be referenced in a different size 962169689Skan and M1 is not the same size as M2. If subreg_lowpart_p is false, we 963169689Skan cannot reload just the inside since we might end up with the wrong 964169689Skan register class. But if it is inside a STRICT_LOW_PART, we have 965169689Skan no choice, so we hope we do get the right register class there. */ 966169689Skan 967169689Skan if (in != 0 && GET_CODE (in) == SUBREG 968169689Skan && (subreg_lowpart_p (in) || strict_low) 969169689Skan#ifdef CLASS_CANNOT_CHANGE_MODE 970169689Skan && (class != CLASS_CANNOT_CHANGE_MODE 971169689Skan || ! CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (SUBREG_REG (in)), inmode)) 972169689Skan#endif 973169689Skan && (CONSTANT_P (SUBREG_REG (in)) 974169689Skan || GET_CODE (SUBREG_REG (in)) == PLUS 975169689Skan || strict_low 976169689Skan || (((GET_CODE (SUBREG_REG (in)) == REG 977169689Skan && REGNO (SUBREG_REG (in)) >= FIRST_PSEUDO_REGISTER) 978169689Skan || GET_CODE (SUBREG_REG (in)) == MEM) 979169689Skan && ((GET_MODE_SIZE (inmode) 980169689Skan > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))) 981169689Skan#ifdef LOAD_EXTEND_OP 982169689Skan || (GET_MODE_SIZE (inmode) <= UNITS_PER_WORD 983169689Skan && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) 984169689Skan <= UNITS_PER_WORD) 985169689Skan && (GET_MODE_SIZE (inmode) 986169689Skan > GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))) 987169689Skan && INTEGRAL_MODE_P (GET_MODE (SUBREG_REG (in))) 988169689Skan && LOAD_EXTEND_OP (GET_MODE (SUBREG_REG (in))) != NIL) 989169689Skan#endif 99090075Sobrien#ifdef WORD_REGISTER_OPERATIONS 99190075Sobrien || ((GET_MODE_SIZE (inmode) 99290075Sobrien < GET_MODE_SIZE (GET_MODE (SUBREG_REG (in)))) 99318334Speter && ((GET_MODE_SIZE (inmode) - 1) / UNITS_PER_WORD == 99490075Sobrien ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) - 1) 99590075Sobrien / UNITS_PER_WORD))) 99690075Sobrien#endif 99718334Speter )) 99818334Speter || (GET_CODE (SUBREG_REG (in)) == REG 99918334Speter && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER 1000169689Skan /* The case where out is nonzero 100118334Speter is handled differently in the following statement. */ 100290075Sobrien && (out == 0 || subreg_lowpart_p (in)) 100318334Speter && ((GET_MODE_SIZE (inmode) <= UNITS_PER_WORD 100490075Sobrien && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) 100518334Speter > UNITS_PER_WORD) 100690075Sobrien && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) 1007169689Skan / UNITS_PER_WORD) 1008169689Skan != HARD_REGNO_NREGS (REGNO (SUBREG_REG (in)), 1009169689Skan GET_MODE (SUBREG_REG (in))))) 101090075Sobrien || ! HARD_REGNO_MODE_OK (subreg_regno (in), inmode))) 1011169689Skan#ifdef SECONDARY_INPUT_RELOAD_CLASS 1012169689Skan || (SECONDARY_INPUT_RELOAD_CLASS (class, inmode, in) != NO_REGS 1013169689Skan && (SECONDARY_INPUT_RELOAD_CLASS (class, 1014169689Skan GET_MODE (SUBREG_REG (in)), 1015169689Skan SUBREG_REG (in)) 1016169689Skan == NO_REGS)) 101790075Sobrien#endif 1018169689Skan#ifdef CLASS_CANNOT_CHANGE_MODE 1019169689Skan || (GET_CODE (SUBREG_REG (in)) == REG 102018334Speter && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER 102190075Sobrien && (TEST_HARD_REG_BIT 102290075Sobrien (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE], 102390075Sobrien REGNO (SUBREG_REG (in)))) 102490075Sobrien && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (SUBREG_REG (in)), 102590075Sobrien inmode)) 1026169689Skan#endif 1027169689Skan )) 1028169689Skan { 102918334Speter in_subreg_loc = inloc; 1030169689Skan inloc = &SUBREG_REG (in); 1031169689Skan in = *inloc; 1032169689Skan#if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS) 1033117395Skan if (GET_CODE (in) == MEM) 1034117395Skan /* This is supposed to happen only for paradoxical subregs made by 1035117395Skan combine.c. (SUBREG (MEM)) isn't supposed to occur other ways. */ 1036117395Skan if (GET_MODE_SIZE (GET_MODE (in)) > GET_MODE_SIZE (inmode)) 1037117395Skan abort (); 103890075Sobrien#endif 103990075Sobrien inmode = GET_MODE (in); 104090075Sobrien } 1041169689Skan 1042169689Skan /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where 1043169689Skan either M1 is not valid for R or M2 is wider than a word but we only 1044169689Skan need one word to store an M2-sized quantity in R. 1045169689Skan 1046169689Skan However, we must reload the inner reg *as well as* the subreg in 1047169689Skan that case. */ 1048169689Skan 1049169689Skan /* Similar issue for (SUBREG constant ...) if it was not handled by the 1050169689Skan code above. This can happen if SUBREG_BYTE != 0. */ 1051169689Skan 1052169689Skan if (in != 0 && reload_inner_reg_of_subreg (in, inmode, 0)) 1053169689Skan { 105490075Sobrien enum reg_class in_class = class; 105590075Sobrien 105690075Sobrien if (GET_CODE (SUBREG_REG (in)) == REG) 1057132718Skan in_class 1058132718Skan = find_valid_class (inmode, 1059169689Skan subreg_regno_offset (REGNO (SUBREG_REG (in)), 1060169689Skan GET_MODE (SUBREG_REG (in)), 106118334Speter SUBREG_BYTE (in), 1062169689Skan GET_MODE (in)), 1063169689Skan REGNO (SUBREG_REG (in))); 1064169689Skan 1065169689Skan /* This relies on the fact that emit_reload_insns outputs the 1066169689Skan instructions for input reloads of type RELOAD_OTHER in the same 1067169689Skan order as the reloads. Thus if the outer reload is also of type 106818334Speter RELOAD_OTHER, we are guaranteed that this inner reload will be 106990075Sobrien output before the outer reload. */ 1070169689Skan push_reload (SUBREG_REG (in), NULL_RTX, &SUBREG_REG (in), (rtx *) 0, 107190075Sobrien in_class, VOIDmode, VOIDmode, 0, 0, opnum, type); 1072169689Skan dont_remove_subreg = 1; 107390075Sobrien } 1074169689Skan 1075169689Skan /* Similarly for paradoxical and problematical SUBREGs on the output. 107690075Sobrien Note that there is no reason we need worry about the previous value 1077169689Skan of SUBREG_REG (out); even if wider than out, 1078169689Skan storing in a subreg is entitled to clobber it all 107918334Speter (except in the case of STRICT_LOW_PART, 108090075Sobrien and in that case the constraint should label it input-output.) */ 108118334Speter if (out != 0 && GET_CODE (out) == SUBREG 108218334Speter && (subreg_lowpart_p (out) || strict_low) 108350397Sobrien#ifdef CLASS_CANNOT_CHANGE_MODE 108490075Sobrien && (class != CLASS_CANNOT_CHANGE_MODE 108518334Speter || ! CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (SUBREG_REG (out)), 108618334Speter outmode)) 108718334Speter#endif 108818334Speter && (CONSTANT_P (SUBREG_REG (out)) 108918334Speter || strict_low 1090169689Skan || (((GET_CODE (SUBREG_REG (out)) == REG 1091169689Skan && REGNO (SUBREG_REG (out)) >= FIRST_PSEUDO_REGISTER) 1092169689Skan || GET_CODE (SUBREG_REG (out)) == MEM) 109318334Speter && ((GET_MODE_SIZE (outmode) 109418334Speter > GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))) 109518334Speter#ifdef WORD_REGISTER_OPERATIONS 109690075Sobrien || ((GET_MODE_SIZE (outmode) 109790075Sobrien < GET_MODE_SIZE (GET_MODE (SUBREG_REG (out)))) 109818334Speter && ((GET_MODE_SIZE (outmode) - 1) / UNITS_PER_WORD == 109990075Sobrien ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) - 1) 110090075Sobrien / UNITS_PER_WORD))) 110118334Speter#endif 110218334Speter )) 110390075Sobrien || (GET_CODE (SUBREG_REG (out)) == REG 110418334Speter && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER 110518334Speter && ((GET_MODE_SIZE (outmode) <= UNITS_PER_WORD 110618334Speter && (GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) 110790075Sobrien > UNITS_PER_WORD) 1108169689Skan && ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (out))) 110990075Sobrien / UNITS_PER_WORD) 111090075Sobrien != HARD_REGNO_NREGS (REGNO (SUBREG_REG (out)), 1111169689Skan GET_MODE (SUBREG_REG (out))))) 111218334Speter || ! HARD_REGNO_MODE_OK (subreg_regno (out), outmode))) 111318334Speter#ifdef SECONDARY_OUTPUT_RELOAD_CLASS 111418334Speter || (SECONDARY_OUTPUT_RELOAD_CLASS (class, outmode, out) != NO_REGS 111590075Sobrien && (SECONDARY_OUTPUT_RELOAD_CLASS (class, 111690075Sobrien GET_MODE (SUBREG_REG (out)), 111790075Sobrien SUBREG_REG (out)) 111818334Speter == NO_REGS)) 111990075Sobrien#endif 112090075Sobrien#ifdef CLASS_CANNOT_CHANGE_MODE 112190075Sobrien || (GET_CODE (SUBREG_REG (out)) == REG 1122169689Skan && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER 1123169689Skan && (TEST_HARD_REG_BIT 1124169689Skan (reg_class_contents[(int) CLASS_CANNOT_CHANGE_MODE], 1125169689Skan REGNO (SUBREG_REG (out)))) 1126169689Skan && CLASS_CANNOT_CHANGE_MODE_P (GET_MODE (SUBREG_REG (out)), 1127169689Skan outmode)) 1128169689Skan#endif 1129169689Skan )) 1130169689Skan { 1131169689Skan out_subreg_loc = outloc; 1132169689Skan outloc = &SUBREG_REG (out); 113318334Speter out = *outloc; 113490075Sobrien#if ! defined (LOAD_EXTEND_OP) && ! defined (WORD_REGISTER_OPERATIONS) 113590075Sobrien if (GET_CODE (out) == MEM 113690075Sobrien && GET_MODE_SIZE (GET_MODE (out)) > GET_MODE_SIZE (outmode)) 113790075Sobrien abort (); 113890075Sobrien#endif 113990075Sobrien outmode = GET_MODE (out); 114090075Sobrien } 114118334Speter 1142117395Skan /* Similar issue for (SUBREG:M1 (REG:M2 ...) ...) for a hard register R where 1143117395Skan either M1 is not valid for R or M2 is wider than a word but we only 1144117395Skan need one word to store an M2-sized quantity in R. 1145117395Skan 1146169689Skan However, we must reload the inner reg *as well as* the subreg in 1147169689Skan that case. In this case, the inner reg is an in-out reload. */ 1148169689Skan 1149169689Skan if (out != 0 && reload_inner_reg_of_subreg (out, outmode, 1)) 1150132718Skan { 1151169689Skan /* This relies on the fact that emit_reload_insns outputs the 115218334Speter instructions for output reloads of type RELOAD_OTHER in reverse 1153132718Skan order of the reloads. Thus if the outer reload is also of type 115490075Sobrien RELOAD_OTHER, we are guaranteed that this inner reload will be 115590075Sobrien output after the outer reload. */ 115690075Sobrien dont_remove_subreg = 1; 115790075Sobrien push_reload (SUBREG_REG (out), SUBREG_REG (out), &SUBREG_REG (out), 115890075Sobrien &SUBREG_REG (out), 115990075Sobrien find_valid_class (outmode, 116090075Sobrien subreg_regno_offset (REGNO (SUBREG_REG (out)), 116190075Sobrien GET_MODE (SUBREG_REG (out)), 1162169689Skan SUBREG_BYTE (out), 116318334Speter GET_MODE (out)), 1164169689Skan REGNO (SUBREG_REG (out))), 1165169689Skan VOIDmode, VOIDmode, 0, 0, 1166169689Skan opnum, RELOAD_OTHER); 116718334Speter } 116818334Speter 116918334Speter /* If IN appears in OUT, we can't share any input-only reload for IN. */ 117018334Speter if (in != 0 && out != 0 && GET_CODE (out) == MEM 117118334Speter && (GET_CODE (in) == REG || GET_CODE (in) == MEM) 117218334Speter && reg_overlap_mentioned_for_reload_p (in, XEXP (out, 0))) 1173132718Skan dont_share = 1; 117418334Speter 117518334Speter /* If IN is a SUBREG of a hard register, make a new REG. This 117618334Speter simplifies some of the cases below. */ 117718334Speter 117818334Speter if (in != 0 && GET_CODE (in) == SUBREG && GET_CODE (SUBREG_REG (in)) == REG 117918334Speter && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER 118018334Speter && ! dont_remove_subreg) 118118334Speter in = gen_rtx_REG (GET_MODE (in), subreg_regno (in)); 118218334Speter 118390075Sobrien /* Similarly for OUT. */ 118490075Sobrien if (out != 0 && GET_CODE (out) == SUBREG 118590075Sobrien && GET_CODE (SUBREG_REG (out)) == REG 118618334Speter && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER 118790075Sobrien && ! dont_remove_subreg) 1188169689Skan out = gen_rtx_REG (GET_MODE (out), subreg_regno (out)); 1189169689Skan 119090075Sobrien /* Narrow down the class of register wanted if that is 1191169689Skan desirable on this machine for efficiency. */ 119290075Sobrien if (in != 0) 119390075Sobrien class = PREFERRED_RELOAD_CLASS (in, class); 119490075Sobrien 1195169689Skan /* Output reloads may need analogous treatment, different in detail. */ 1196169689Skan#ifdef PREFERRED_OUTPUT_RELOAD_CLASS 1197169689Skan if (out != 0) 1198169689Skan class = PREFERRED_OUTPUT_RELOAD_CLASS (out, class); 1199169689Skan#endif 120090075Sobrien 120118334Speter /* Make sure we use a class that can handle the actual pseudo 120290075Sobrien inside any subreg. For example, on the 386, QImode regs 1203132718Skan can appear within SImode subregs. Although GENERAL_REGS 120490075Sobrien can handle SImode, QImode needs a smaller class. */ 120590075Sobrien#ifdef LIMIT_RELOAD_CLASS 120690075Sobrien if (in_subreg_loc) 120718334Speter class = LIMIT_RELOAD_CLASS (inmode, class); 120890075Sobrien else if (in != 0 && GET_CODE (in) == SUBREG) 120990075Sobrien class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (in)), class); 121090075Sobrien 121190075Sobrien if (out_subreg_loc) 121290075Sobrien class = LIMIT_RELOAD_CLASS (outmode, class); 121390075Sobrien if (out != 0 && GET_CODE (out) == SUBREG) 121490075Sobrien class = LIMIT_RELOAD_CLASS (GET_MODE (SUBREG_REG (out)), class); 121590075Sobrien#endif 121690075Sobrien 121790075Sobrien /* Verify that this class is at least possible for the mode that 121890075Sobrien is specified. */ 1219169689Skan if (this_insn_is_asm) 122090075Sobrien { 122190075Sobrien enum machine_mode mode; 122290075Sobrien if (GET_MODE_SIZE (inmode) > GET_MODE_SIZE (outmode)) 122390075Sobrien mode = inmode; 122490075Sobrien else 122518334Speter mode = outmode; 1226132718Skan if (mode == VOIDmode) 1227132718Skan { 122890075Sobrien error_for_asm (this_insn, "cannot reload integer constant operand in `asm'"); 1229169689Skan mode = word_mode; 123090075Sobrien if (in != 0) 123190075Sobrien inmode = word_mode; 123290075Sobrien if (out != 0) 123390075Sobrien outmode = word_mode; 123490075Sobrien } 123518334Speter for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) 123618334Speter if (HARD_REGNO_MODE_OK (i, mode) 123718334Speter && TEST_HARD_REG_BIT (reg_class_contents[(int) class], i)) 1238169689Skan { 1239169689Skan int nregs = HARD_REGNO_NREGS (i, mode); 124018334Speter 1241169689Skan int j; 124290075Sobrien for (j = 1; j < nregs; j++) 124390075Sobrien if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], i + j)) 124490075Sobrien break; 1245169689Skan if (j == nregs) 1246169689Skan break; 1247169689Skan } 1248169689Skan if (i == FIRST_PSEUDO_REGISTER) 1249169689Skan { 125090075Sobrien error_for_asm (this_insn, "impossible register constraint in `asm'"); 125190075Sobrien class = ALL_REGS; 125290075Sobrien } 1253132718Skan } 125490075Sobrien 125590075Sobrien /* Optional output reloads are always OK even if we have no register class, 125690075Sobrien since the function of these reloads is only to have spill_reg_store etc. 125790075Sobrien set, so that the storing insn can be deleted later. */ 125890075Sobrien if (class == NO_REGS 125990075Sobrien && (optional == 0 || type != RELOAD_FOR_OUTPUT)) 126018334Speter abort (); 126190075Sobrien 126290075Sobrien i = find_reusable_reload (&in, out, class, type, opnum, dont_share); 126390075Sobrien 126490075Sobrien if (i == n_reloads) 126590075Sobrien { 126690075Sobrien /* See if we need a secondary reload register to move between CLASS 126718334Speter and IN or CLASS and OUT. Get the icode and push any required reloads 126890075Sobrien needed for each of them if so. */ 1269169689Skan 127090075Sobrien#ifdef SECONDARY_INPUT_RELOAD_CLASS 127190075Sobrien if (in != 0) 127218334Speter secondary_in_reload 127318334Speter = push_secondary_reload (1, in, opnum, optional, class, inmode, type, 127490075Sobrien &secondary_in_icode); 127518334Speter#endif 1276132718Skan 1277132718Skan#ifdef SECONDARY_OUTPUT_RELOAD_CLASS 127890075Sobrien if (out != 0 && GET_CODE (out) != SCRATCH) 1279169689Skan secondary_out_reload 128090075Sobrien = push_secondary_reload (0, out, opnum, optional, class, outmode, 128190075Sobrien type, &secondary_out_icode); 128290075Sobrien#endif 128318334Speter 128418334Speter /* We found no existing reload suitable for re-use. 128550397Sobrien So add an additional reload. */ 1286117395Skan 128750397Sobrien#ifdef SECONDARY_MEMORY_NEEDED 128850397Sobrien { 128950397Sobrien int regnum; 129050397Sobrien 129150397Sobrien /* If a memory location is needed for the copy, make one. */ 129250397Sobrien if (in != 0 129350397Sobrien && ((regnum = true_regnum (in)) >= 0) 129450397Sobrien && regnum < FIRST_PSEUDO_REGISTER 1295132718Skan && SECONDARY_MEMORY_NEEDED (REGNO_REG_CLASS (regnum), 1296132718Skan class, inmode)) 1297132718Skan get_secondary_mem (in, inmode, opnum, type); 1298132718Skan } 1299132718Skan#endif 1300132718Skan 1301132718Skan i = n_reloads; 1302132718Skan rld[i].in = in; 1303132718Skan rld[i].out = out; 1304132718Skan rld[i].class = class; 1305169689Skan rld[i].inmode = inmode; 1306169689Skan rld[i].outmode = outmode; 1307132718Skan rld[i].reg_rtx = 0; 1308132718Skan rld[i].optional = optional; 1309132718Skan rld[i].inc = 0; 1310132718Skan rld[i].nocombine = 0; 1311132718Skan rld[i].in_reg = inloc ? *inloc : 0; 1312132718Skan rld[i].out_reg = outloc ? *outloc : 0; 1313169689Skan rld[i].opnum = opnum; 1314132718Skan rld[i].when_needed = type; 1315132718Skan rld[i].secondary_in_reload = secondary_in_reload; 1316169689Skan rld[i].secondary_out_reload = secondary_out_reload; 1317132718Skan rld[i].secondary_in_icode = secondary_in_icode; 1318132718Skan rld[i].secondary_out_icode = secondary_out_icode; 1319132718Skan rld[i].secondary_p = 0; 1320132718Skan 1321132718Skan n_reloads++; 1322132718Skan 1323132718Skan#ifdef SECONDARY_MEMORY_NEEDED 1324169689Skan { 1325132718Skan int regnum; 1326132718Skan 1327169689Skan if (out != 0 1328169689Skan && ((regnum = true_regnum (out)) >= 0) 1329132718Skan && regnum < FIRST_PSEUDO_REGISTER 1330132718Skan && SECONDARY_MEMORY_NEEDED (class, REGNO_REG_CLASS (regnum), 1331132718Skan outmode)) 1332132718Skan get_secondary_mem (out, outmode, opnum, type); 1333132718Skan } 133418334Speter#endif 133518334Speter } 133618334Speter else 133718334Speter { 133818334Speter /* We are reusing an existing reload, 133918334Speter but we may have additional information for it. 1340132718Skan For example, we may now have both IN and OUT 134118334Speter while the old one may have just one of them. */ 134218334Speter 1343169689Skan /* The modes can be different. If they are, we want to reload in 1344169689Skan the larger mode, so that the value is valid for both modes. */ 134518334Speter if (inmode != VOIDmode 1346169689Skan && GET_MODE_SIZE (inmode) > GET_MODE_SIZE (rld[i].inmode)) 1347169689Skan rld[i].inmode = inmode; 1348169689Skan if (outmode != VOIDmode 1349169689Skan && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (rld[i].outmode)) 1350169689Skan rld[i].outmode = outmode; 1351169689Skan if (in != 0) 1352169689Skan { 1353169689Skan rtx in_reg = inloc ? *inloc : 0; 1354169689Skan /* If we merge reloads for two distinct rtl expressions that 1355169689Skan are identical in content, there might be duplicate address 1356169689Skan reloads. Remove the extra set now, so that if we later find 1357169689Skan that we can inherit this reload, we can get rid of the 1358169689Skan address reloads altogether. 1359169689Skan 1360169689Skan Do not do this if both reloads are optional since the result 1361169689Skan would be an optional reload which could potentially leave 1362169689Skan unresolved address replacements. 1363169689Skan 1364169689Skan It is not sufficient to call transfer_replacements since 1365169689Skan choose_reload_regs will remove the replacements for address 1366169689Skan reloads of inherited reloads which results in the same 1367169689Skan problem. */ 1368169689Skan if (rld[i].in != in && rtx_equal_p (in, rld[i].in) 136918334Speter && ! (rld[i].optional && optional)) 137018334Speter { 137118334Speter /* We must keep the address reload with the lower operand 137218334Speter number alive. */ 137350397Sobrien if (opnum > rld[i].opnum) 137450397Sobrien { 137518334Speter remove_address_replacements (in); 1376102780Skan in = rld[i].in; 137718334Speter in_reg = rld[i].in_reg; 1378169689Skan } 1379169689Skan else 1380169689Skan remove_address_replacements (rld[i].in); 1381169689Skan } 1382169689Skan rld[i].in = in; 1383169689Skan rld[i].in_reg = in_reg; 1384169689Skan } 1385169689Skan if (out != 0) 1386259694Spfg { 1387169689Skan rld[i].out = out; 1388169689Skan rld[i].out_reg = outloc ? *outloc : 0; 1389169689Skan } 1390169689Skan if (reg_class_subset_p (class, rld[i].class)) 1391169689Skan rld[i].class = class; 1392169689Skan rld[i].optional &= optional; 1393169689Skan if (MERGE_TO_OTHER (type, rld[i].when_needed, 1394169689Skan opnum, rld[i].opnum)) 1395169689Skan rld[i].when_needed = RELOAD_OTHER; 1396259694Spfg rld[i].opnum = MIN (rld[i].opnum, opnum); 1397169689Skan } 1398169689Skan 1399169689Skan /* If the ostensible rtx being reloaded differs from the rtx found 1400169689Skan in the location to substitute, this reload is not safe to combine 1401169689Skan because we cannot reliably tell whether it appears in the insn. */ 1402169689Skan 1403169689Skan if (in != 0 && in != *inloc) 1404169689Skan rld[i].nocombine = 1; 1405169689Skan 1406169689Skan#if 0 1407169689Skan /* This was replaced by changes in find_reloads_address_1 and the new 1408169689Skan function inc_for_reload, which go with a new meaning of reload_inc. */ 1409169689Skan 1410169689Skan /* If this is an IN/OUT reload in an insn that sets the CC, 1411169689Skan it must be for an autoincrement. It doesn't work to store 1412169689Skan the incremented value after the insn because that would clobber the CC. 1413169689Skan So we must do the increment of the value reloaded from, 1414169689Skan increment it, store it back, then decrement again. */ 1415169689Skan if (out != 0 && sets_cc0_p (PATTERN (this_insn))) 1416169689Skan { 1417169689Skan out = 0; 1418169689Skan rld[i].out = 0; 1419169689Skan rld[i].inc = find_inc_amount (PATTERN (this_insn), in); 1420169689Skan /* If we did not find a nonzero amount-to-increment-by, 1421169689Skan that contradicts the belief that IN is being incremented 1422169689Skan in an address in this insn. */ 1423169689Skan if (rld[i].inc == 0) 1424169689Skan abort (); 1425169689Skan } 142618334Speter#endif 1427259694Spfg 142818334Speter /* If we will replace IN and OUT with the reload-reg, 142990075Sobrien record where they are located so that substitution need 143090075Sobrien not do a tree walk. */ 143190075Sobrien 143218334Speter if (replace_reloads) 143390075Sobrien { 1434259694Spfg if (inloc != 0) 143590075Sobrien { 1436259694Spfg struct replacement *r = &replacements[n_replacements++]; 1437259694Spfg r->what = i; 1438117395Skan r->subreg_loc = in_subreg_loc; 143990075Sobrien r->where = inloc; 144090075Sobrien r->mode = inmode; 144190075Sobrien } 1442117395Skan if (outloc != 0 && outloc != inloc) 144390075Sobrien { 144490075Sobrien struct replacement *r = &replacements[n_replacements++]; 144590075Sobrien r->what = i; 144690075Sobrien r->where = outloc; 144790075Sobrien r->subreg_loc = out_subreg_loc; 144818334Speter r->mode = outmode; 144918334Speter } 145018334Speter } 145118334Speter 145290075Sobrien /* If this reload is just being introduced and it has both 145318334Speter an incoming quantity and an outgoing quantity that are 145418334Speter supposed to be made to match, see if either one of the two 145518334Speter can serve as the place to reload into. 145618334Speter 145718334Speter If one of them is acceptable, set rld[i].reg_rtx 1458132718Skan to that one. */ 145918334Speter 146096263Sobrien if (in != 0 && out != 0 && in != out && rld[i].reg_rtx == 0) 1461117395Skan { 1462117395Skan rld[i].reg_rtx = find_dummy_reload (in, out, inloc, outloc, 146318334Speter inmode, outmode, 146418334Speter rld[i].class, i, 1465169689Skan earlyclobber_operand_p (out)); 1466169689Skan 1467169689Skan /* If the outgoing register already contains the same value 1468132718Skan as the incoming one, we can dispense with loading it. 146918334Speter The easiest way to tell the caller that is to give a phony 147018334Speter value for the incoming operand (same as outgoing one). */ 147118334Speter if (rld[i].reg_rtx == out 147218334Speter && (GET_CODE (in) == REG || CONSTANT_P (in)) 147350397Sobrien && 0 != find_equiv_reg (in, this_insn, 0, REGNO (out), 147418334Speter static_reload_reg_p, i, inmode)) 147518334Speter rld[i].in = out; 147618334Speter } 147718334Speter 147818334Speter /* If this is an input reload and the operand contains a register that 147918334Speter dies in this insn and is used nowhere else, see if it is the right class 148018334Speter to be used for this reload. Use it if so. (This occurs most commonly 1481169689Skan in the case of paradoxical SUBREGs and in-out reloads). We cannot do 148218334Speter this if it is also an output reload that mentions the register unless 148318334Speter the output is a SUBREG that clobbers an entire register. 1484169689Skan 1485169689Skan Note that the operand might be one of the spill regs, if it is a 1486169689Skan pseudo reg and we are in a block where spilling has not taken place. 148718334Speter But if there is no spilling in this block, that is OK. 148818334Speter An explicitly used hard reg cannot be a spill reg. */ 148950397Sobrien 149050397Sobrien if (rld[i].reg_rtx == 0 && in != 0) 149150397Sobrien { 1492169689Skan rtx note; 149350397Sobrien int regno; 1494169689Skan enum machine_mode rel_mode = inmode; 1495169689Skan 1496169689Skan if (out && GET_MODE_SIZE (outmode) > GET_MODE_SIZE (inmode)) 1497169689Skan rel_mode = outmode; 1498169689Skan 1499169689Skan for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1)) 1500169689Skan if (REG_NOTE_KIND (note) == REG_DEAD 1501169689Skan && GET_CODE (XEXP (note, 0)) == REG 1502169689Skan && (regno = REGNO (XEXP (note, 0))) < FIRST_PSEUDO_REGISTER 1503169689Skan && reg_mentioned_p (XEXP (note, 0), in) 1504169689Skan && ! refers_to_regno_for_reload_p (regno, 1505169689Skan (regno 1506169689Skan + HARD_REGNO_NREGS (regno, 1507169689Skan rel_mode)), 1508169689Skan PATTERN (this_insn), inloc) 1509169689Skan /* If this is also an output reload, IN cannot be used as 151018334Speter the reload register if it is set in this insn unless IN 151118334Speter is also OUT. */ 151218334Speter && (out == 0 || in == out 151318334Speter || ! hard_reg_set_here_p (regno, 151418334Speter (regno 1515132718Skan + HARD_REGNO_NREGS (regno, 151618334Speter rel_mode)), 151752284Sobrien PATTERN (this_insn))) 151852284Sobrien /* ??? Why is this code so different from the previous? 151952284Sobrien Is there any simple coherent way to describe the two together? 152052284Sobrien What's going on here. */ 152118334Speter && (in != out 152218334Speter || (GET_CODE (in) == SUBREG 152318334Speter && (((GET_MODE_SIZE (GET_MODE (in)) + (UNITS_PER_WORD - 1)) 1524169689Skan / UNITS_PER_WORD) 152518334Speter == ((GET_MODE_SIZE (GET_MODE (SUBREG_REG (in))) 1526132718Skan + (UNITS_PER_WORD - 1)) / UNITS_PER_WORD)))) 152790075Sobrien /* Make sure the operand fits in the reg that dies. */ 152890075Sobrien && (GET_MODE_SIZE (rel_mode) 152918334Speter <= GET_MODE_SIZE (GET_MODE (XEXP (note, 0)))) 153018334Speter && HARD_REGNO_MODE_OK (regno, inmode) 153118334Speter && HARD_REGNO_MODE_OK (regno, outmode)) 153218334Speter { 153350397Sobrien unsigned int offs; 153418334Speter unsigned int nregs = MAX (HARD_REGNO_NREGS (regno, inmode), 153518334Speter HARD_REGNO_NREGS (regno, outmode)); 153618334Speter 153718334Speter for (offs = 0; offs < nregs; offs++) 153818334Speter if (fixed_regs[regno + offs] 1539132718Skan || ! TEST_HARD_REG_BIT (reg_class_contents[(int) class], 154018334Speter regno + offs)) 154118334Speter break; 154290075Sobrien 154390075Sobrien if (offs == nregs) 154490075Sobrien { 154518334Speter rld[i].reg_rtx = gen_rtx_REG (rel_mode, regno); 154618334Speter break; 154718334Speter } 154818334Speter } 154918334Speter } 1550132718Skan 155118334Speter if (out) 155218334Speter output_reloadnum = i; 155318334Speter 155418334Speter return i; 155518334Speter} 155618334Speter 155718334Speter/* Record an additional place we must replace a value 155818334Speter for which we have already recorded a reload. 155918334Speter RELOADNUM is the value returned by push_reload 156018334Speter when the reload was recorded. 156118334Speter This is used in insn patterns that use match_dup. */ 156218334Speter 156350397Sobrienstatic void 156418334Speterpush_replacement (loc, reloadnum, mode) 156518334Speter rtx *loc; 156618334Speter int reloadnum; 156718334Speter enum machine_mode mode; 156818334Speter{ 156918334Speter if (replace_reloads) 157018334Speter { 1571169689Skan struct replacement *r = &replacements[n_replacements++]; 1572169689Skan r->what = reloadnum; 1573169689Skan r->where = loc; 1574169689Skan r->subreg_loc = 0; 1575169689Skan r->mode = mode; 1576169689Skan } 1577169689Skan} 1578169689Skan 1579169689Skan/* Transfer all replacements that used to be in reload FROM to be in 1580169689Skan reload TO. */ 1581169689Skan 1582169689Skanvoid 1583169689Skantransfer_replacements (to, from) 1584169689Skan int to, from; 1585169689Skan{ 158690075Sobrien int i; 1587169689Skan 1588169689Skan for (i = 0; i < n_replacements; i++) 158990075Sobrien if (replacements[i].what == from) 1590169689Skan replacements[i].what = to; 159190075Sobrien} 1592169689Skan 1593169689Skan/* IN_RTX is the value loaded by a reload that we now decided to inherit, 1594169689Skan or a subpart of it. If we have any replacements registered for IN_RTX, 1595169689Skan cancel the reloads that were supposed to load them. 1596169689Skan Return non-zero if we canceled any reloads. */ 1597169689Skanint 1598169689Skanremove_address_replacements (in_rtx) 1599169689Skan rtx in_rtx; 1600169689Skan{ 160190075Sobrien int i, j; 1602169689Skan char reload_flags[MAX_RELOADS]; 1603169689Skan int something_changed = 0; 160490075Sobrien 1605169689Skan memset (reload_flags, 0, sizeof reload_flags); 1606169689Skan for (i = 0, j = 0; i < n_replacements; i++) 160790075Sobrien { 1608169689Skan if (loc_mentioned_in_p (replacements[i].where, in_rtx)) 160990075Sobrien reload_flags[replacements[i].what] |= 1; 161090075Sobrien else 1611169689Skan { 1612169689Skan replacements[j++] = replacements[i]; 1613169689Skan reload_flags[replacements[i].what] |= 2; 1614169689Skan } 1615169689Skan } 1616169689Skan /* Note that the following store must be done before the recursive calls. */ 1617169689Skan n_replacements = j; 1618169689Skan 161990075Sobrien for (i = n_reloads - 1; i >= 0; i--) 1620169689Skan { 1621169689Skan if (reload_flags[i] == 1) 1622169689Skan { 1623169689Skan deallocate_reload_reg (i); 1624169689Skan remove_address_replacements (rld[i].in); 1625169689Skan rld[i].in = 0; 162690075Sobrien something_changed = 1; 1627169689Skan } 1628169689Skan } 162990075Sobrien return something_changed; 1630169689Skan} 163190075Sobrien 1632169689Skan/* If there is only one output reload, and it is not for an earlyclobber 1633169689Skan operand, try to combine it with a (logically unrelated) input reload 1634117395Skan to reduce the number of reload registers needed. 1635169689Skan 1636169689Skan This is safe if the input reload does not appear in 1637169689Skan the value being output-reloaded, because this implies 1638169689Skan it is not needed any more once the original insn completes. 163990075Sobrien 1640169689Skan If that doesn't work, see we can use any of the registers that 1641169689Skan die in this insn as a reload register. We can if it is of the right 1642169689Skan class and does not appear in the value being output-reloaded. */ 1643117395Skan 1644169689Skanstatic void 1645169689Skancombine_reloads () 1646117395Skan{ 1647169689Skan int i; 164890075Sobrien int output_reload = -1; 1649169689Skan int secondary_out = -1; 1650169689Skan rtx note; 165196263Sobrien 1652169689Skan /* Find the output reload; return unless there is exactly one 1653169689Skan and that one is mandatory. */ 1654169689Skan 1655169689Skan for (i = 0; i < n_reloads; i++) 165690075Sobrien if (rld[i].out != 0) 1657169689Skan { 1658169689Skan if (output_reload >= 0) 1659169689Skan return; 1660169689Skan output_reload = i; 1661169689Skan } 1662169689Skan 1663169689Skan if (output_reload < 0 || rld[output_reload].optional) 1664169689Skan return; 1665169689Skan 1666169689Skan /* An input-output reload isn't combinable. */ 1667169689Skan 1668169689Skan if (rld[output_reload].in != 0) 1669169689Skan return; 1670169689Skan 1671169689Skan /* If this reload is for an earlyclobber operand, we can't do anything. */ 1672169689Skan if (earlyclobber_operand_p (rld[output_reload].out)) 1673169689Skan return; 1674169689Skan 1675169689Skan /* If there is a reload for part of the address of this operand, we would 1676169689Skan need to chnage it to RELOAD_FOR_OTHER_ADDRESS. But that would extend 1677169689Skan its life to the point where doing this combine would not lower the 1678169689Skan number of spill registers needed. */ 1679169689Skan for (i = 0; i < n_reloads; i++) 1680169689Skan if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS 1681169689Skan || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS) 1682169689Skan && rld[i].opnum == rld[output_reload].opnum) 1683169689Skan return; 1684169689Skan 1685169689Skan /* Check each input reload; can we combine it? */ 1686169689Skan 1687169689Skan for (i = 0; i < n_reloads; i++) 1688169689Skan if (rld[i].in && ! rld[i].optional && ! rld[i].nocombine 1689169689Skan /* Life span of this reload must not extend past main insn. */ 1690169689Skan && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS 1691169689Skan && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS 1692169689Skan && rld[i].when_needed != RELOAD_OTHER 1693169689Skan && (CLASS_MAX_NREGS (rld[i].class, rld[i].inmode) 1694169689Skan == CLASS_MAX_NREGS (rld[output_reload].class, 169590075Sobrien rld[output_reload].outmode)) 1696169689Skan && rld[i].inc == 0 1697169689Skan && rld[i].reg_rtx == 0 1698169689Skan#ifdef SECONDARY_MEMORY_NEEDED 1699169689Skan /* Don't combine two reloads with different secondary 1700169689Skan memory locations. */ 1701169689Skan && (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum] == 0 1702169689Skan || secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] == 0 1703169689Skan || rtx_equal_p (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum], 1704169689Skan secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum])) 1705169689Skan#endif 170690075Sobrien && (SMALL_REGISTER_CLASSES 170790075Sobrien ? (rld[i].class == rld[output_reload].class) 170890075Sobrien : (reg_class_subset_p (rld[i].class, 170918334Speter rld[output_reload].class) 171018334Speter || reg_class_subset_p (rld[output_reload].class, 171118334Speter rld[i].class))) 171218334Speter && (MATCHES (rld[i].in, rld[output_reload].out) 171318334Speter /* Args reversed because the first arg seems to be 171418334Speter the one that we imagine being modified 171518334Speter while the second is the one that might be affected. */ 171618334Speter || (! reg_overlap_mentioned_for_reload_p (rld[output_reload].out, 171718334Speter rld[i].in) 171818334Speter /* However, if the input is a register that appears inside 171918334Speter the output, then we also can't share. 1720132718Skan Imagine (set (mem (reg 69)) (plus (reg 69) ...)). 1721132718Skan If the same reload reg is used for both reg 69 and the 172218334Speter result to be stored in memory, then that result 172390075Sobrien will clobber the address of the memory ref. */ 1724169689Skan && ! (GET_CODE (rld[i].in) == REG 1725169689Skan && reg_overlap_mentioned_for_reload_p (rld[i].in, 172618334Speter rld[output_reload].out)))) 1727132718Skan && ! reload_inner_reg_of_subreg (rld[i].in, rld[i].inmode, 1728169689Skan rld[i].when_needed != RELOAD_FOR_INPUT) 1729132718Skan && (reg_class_size[(int) rld[i].class] 173018334Speter || SMALL_REGISTER_CLASSES) 173118334Speter /* We will allow making things slightly worse by combining an 173218334Speter input and an output, but no worse than that. */ 173318334Speter && (rld[i].when_needed == RELOAD_FOR_INPUT 173418334Speter || rld[i].when_needed == RELOAD_FOR_OUTPUT)) 173518334Speter { 173618334Speter int j; 173718334Speter 173818334Speter /* We have found a reload to combine with! */ 173918334Speter rld[i].out = rld[output_reload].out; 174018334Speter rld[i].out_reg = rld[output_reload].out_reg; 174118334Speter rld[i].outmode = rld[output_reload].outmode; 174218334Speter /* Mark the old output reload as inoperative. */ 174318334Speter rld[output_reload].out = 0; 174418334Speter /* The combined reload is needed for the entire insn. */ 174590075Sobrien rld[i].when_needed = RELOAD_OTHER; 1746169689Skan /* If the output reload had a secondary reload, copy it. */ 174790075Sobrien if (rld[output_reload].secondary_out_reload != -1) 174890075Sobrien { 174990075Sobrien rld[i].secondary_out_reload 175090075Sobrien = rld[output_reload].secondary_out_reload; 175190075Sobrien rld[i].secondary_out_icode 175218334Speter = rld[output_reload].secondary_out_icode; 175318334Speter } 175418334Speter 175518334Speter#ifdef SECONDARY_MEMORY_NEEDED 175618334Speter /* Copy any secondary MEM. */ 175718334Speter if (secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum] != 0) 175818334Speter secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[i].opnum] 175918334Speter = secondary_memlocs_elim[(int) rld[output_reload].outmode][rld[output_reload].opnum]; 176018334Speter#endif 176118334Speter /* If required, minimize the register class. */ 176218334Speter if (reg_class_subset_p (rld[output_reload].class, 1763169689Skan rld[i].class)) 176418334Speter rld[i].class = rld[output_reload].class; 176518334Speter 176618334Speter /* Transfer all replacements from the old reload to the combined. */ 176718334Speter for (j = 0; j < n_replacements; j++) 176818334Speter if (replacements[j].what == output_reload) 176918334Speter replacements[j].what = i; 177018334Speter 177118334Speter return; 177218334Speter } 177318334Speter 177418334Speter /* If this insn has only one operand that is modified or written (assumed 177518334Speter to be the first), it must be the one corresponding to this reload. It 1776117395Skan is safe to use anything that dies in this insn for that output provided 1777117395Skan that it does not occur in the output (we already know it isn't an 177890075Sobrien earlyclobber. If this is an asm insn, give up. */ 177990075Sobrien 178018334Speter if (INSN_CODE (this_insn) == -1) 178118334Speter return; 178252284Sobrien 178352284Sobrien for (i = 1; i < insn_data[INSN_CODE (this_insn)].n_operands; i++) 178452284Sobrien if (insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '=' 178552284Sobrien || insn_data[INSN_CODE (this_insn)].operand[i].constraint[0] == '+') 178618334Speter return; 178718334Speter 178890075Sobrien /* See if some hard register that dies in this insn and is not used in 178990075Sobrien the output is the right class. Only works if the register we pick 179018334Speter up can fully hold our output reload. */ 1791169689Skan for (note = REG_NOTES (this_insn); note; note = XEXP (note, 1)) 179290075Sobrien if (REG_NOTE_KIND (note) == REG_DEAD 179318334Speter && GET_CODE (XEXP (note, 0)) == REG 179418334Speter && ! reg_overlap_mentioned_for_reload_p (XEXP (note, 0), 1795169689Skan rld[output_reload].out) 1796169689Skan && REGNO (XEXP (note, 0)) < FIRST_PSEUDO_REGISTER 1797169689Skan && HARD_REGNO_MODE_OK (REGNO (XEXP (note, 0)), rld[output_reload].outmode) 1798169689Skan && TEST_HARD_REG_BIT (reg_class_contents[(int) rld[output_reload].class], 1799132718Skan REGNO (XEXP (note, 0))) 1800132718Skan && (HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), rld[output_reload].outmode) 180150397Sobrien <= HARD_REGNO_NREGS (REGNO (XEXP (note, 0)), GET_MODE (XEXP (note, 0)))) 180250397Sobrien /* Ensure that a secondary or tertiary reload for this output 180350397Sobrien won't want this register. */ 1804169689Skan && ((secondary_out = rld[output_reload].secondary_out_reload) == -1 1805169689Skan || (! (TEST_HARD_REG_BIT 180650397Sobrien (reg_class_contents[(int) rld[secondary_out].class], 1807117395Skan REGNO (XEXP (note, 0)))) 1808117395Skan && ((secondary_out = rld[secondary_out].secondary_out_reload) == -1 1809117395Skan || ! (TEST_HARD_REG_BIT 1810169689Skan (reg_class_contents[(int) rld[secondary_out].class], 1811169689Skan REGNO (XEXP (note, 0))))))) 1812117395Skan && ! fixed_regs[REGNO (XEXP (note, 0))]) 181318334Speter { 1814169689Skan rld[output_reload].reg_rtx 1815169689Skan = gen_rtx_REG (rld[output_reload].outmode, 1816169689Skan REGNO (XEXP (note, 0))); 1817169689Skan return; 181896263Sobrien } 181918334Speter} 1820169689Skan 1821169689Skan/* Try to find a reload register for an in-out reload (expressions IN and OUT). 1822169689Skan See if one of IN and OUT is a register that may be used; 182350397Sobrien this is desirable since a spill-register won't be needed. 182418334Speter If so, return the register rtx that proves acceptable. 1825169689Skan 182618334Speter INLOC and OUTLOC are locations where IN and OUT appear in the insn. 182718334Speter CLASS is the register class required for the reload. 1828169689Skan 1829169689Skan If FOR_REAL is >= 0, it is the number of the reload, 1830169689Skan and in some cases when it can be discovered that OUT doesn't need 1831169689Skan to be computed, clear out rld[FOR_REAL].out. 183290075Sobrien 1833169689Skan If FOR_REAL is -1, this should not be done, because this call 1834169689Skan is just to see if a register can be found, not to find and install it. 183590075Sobrien 1836169689Skan EARLYCLOBBER is non-zero if OUT is an earlyclobber operand. This 1837169689Skan puts an additional constraint on being able to use IN for OUT since 1838169689Skan IN must not appear elsewhere in the insn (it is assumed that IN itself 183918334Speter is safe from the earlyclobber). */ 1840169689Skan 1841169689Skanstatic rtx 1842169689Skanfind_dummy_reload (real_in, real_out, inloc, outloc, 1843169689Skan inmode, outmode, class, for_real, earlyclobber) 184418334Speter rtx real_in, real_out; 184518334Speter rtx *inloc, *outloc; 184618334Speter enum machine_mode inmode, outmode; 184718334Speter enum reg_class class; 184818334Speter int for_real; 184918334Speter int earlyclobber; 1850132718Skan{ 185118334Speter rtx in = real_in; 185218334Speter rtx out = real_out; 185318334Speter int in_offset = 0; 185418334Speter int out_offset = 0; 185518334Speter rtx value = 0; 185618334Speter 185718334Speter /* If operands exceed a word, we can't use either of them 185818334Speter unless they have the same size. */ 185918334Speter if (GET_MODE_SIZE (outmode) != GET_MODE_SIZE (inmode) 186018334Speter && (GET_MODE_SIZE (outmode) > UNITS_PER_WORD 186118334Speter || GET_MODE_SIZE (inmode) > UNITS_PER_WORD)) 186218334Speter return 0; 186318334Speter 186418334Speter /* Note that {in,out}_offset are needed only when 'in' or 'out' 186518334Speter respectively refers to a hard register. */ 186618334Speter 186718334Speter /* Find the inside of any subregs. */ 186818334Speter while (GET_CODE (out) == SUBREG) 186918334Speter { 187018334Speter if (GET_CODE (SUBREG_REG (out)) == REG 187118334Speter && REGNO (SUBREG_REG (out)) < FIRST_PSEUDO_REGISTER) 187218334Speter out_offset += subreg_regno_offset (REGNO (SUBREG_REG (out)), 187318334Speter GET_MODE (SUBREG_REG (out)), 187418334Speter SUBREG_BYTE (out), 187518334Speter GET_MODE (out)); 187618334Speter out = SUBREG_REG (out); 187718334Speter } 187818334Speter while (GET_CODE (in) == SUBREG) 187918334Speter { 188018334Speter if (GET_CODE (SUBREG_REG (in)) == REG 188118334Speter && REGNO (SUBREG_REG (in)) < FIRST_PSEUDO_REGISTER) 188218334Speter in_offset += subreg_regno_offset (REGNO (SUBREG_REG (in)), 1883169689Skan GET_MODE (SUBREG_REG (in)), 1884169689Skan SUBREG_BYTE (in), 1885169689Skan GET_MODE (in)); 1886169689Skan in = SUBREG_REG (in); 1887169689Skan } 1888169689Skan 1889132718Skan /* Narrow down the reg class, the same way push_reload will; 1890132718Skan otherwise we might find a dummy now, but push_reload won't. */ 1891132718Skan class = PREFERRED_RELOAD_CLASS (in, class); 1892132718Skan 1893132718Skan /* See if OUT will do. */ 1894132718Skan if (GET_CODE (out) == REG 1895132718Skan && REGNO (out) < FIRST_PSEUDO_REGISTER) 1896132718Skan { 1897132718Skan unsigned int regno = REGNO (out) + out_offset; 1898132718Skan unsigned int nwords = HARD_REGNO_NREGS (regno, outmode); 1899132718Skan rtx saved_rtx; 1900132718Skan 1901132718Skan /* When we consider whether the insn uses OUT, 1902132718Skan ignore references within IN. They don't prevent us 1903132718Skan from copying IN into OUT, because those refs would 1904132718Skan move into the insn that reloads IN. 1905132718Skan 1906132718Skan However, we only ignore IN in its role as this reload. 1907132718Skan If the insn uses IN elsewhere and it contains OUT, 1908132718Skan that counts. We can't be sure it's the "same" operand 1909132718Skan so it might not go through this reload. */ 1910169689Skan saved_rtx = *inloc; 1911169689Skan *inloc = const0_rtx; 1912169689Skan 1913169689Skan if (regno < FIRST_PSEUDO_REGISTER 1914169689Skan && HARD_REGNO_MODE_OK (regno, outmode) 1915169689Skan && ! refers_to_regno_for_reload_p (regno, regno + nwords, 1916169689Skan PATTERN (this_insn), outloc)) 1917169689Skan { 1918169689Skan unsigned int i; 1919169689Skan 1920169689Skan for (i = 0; i < nwords; i++) 1921169689Skan if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], 1922169689Skan regno + i)) 1923169689Skan break; 1924169689Skan 1925169689Skan if (i == nwords) 1926169689Skan { 1927132718Skan if (GET_CODE (real_out) == REG) 1928132718Skan value = real_out; 1929169689Skan else 1930169689Skan value = gen_rtx_REG (outmode, regno); 1931169689Skan } 1932169689Skan } 1933169689Skan 1934169689Skan *inloc = saved_rtx; 1935169689Skan } 1936169689Skan 1937169689Skan /* Consider using IN if OUT was not acceptable 1938169689Skan or if OUT dies in this insn (like the quotient in a divmod insn). 1939169689Skan We can't use IN unless it is dies in this insn, 1940169689Skan which means we must know accurately which hard regs are live. 194118334Speter Also, the result can't go in IN if IN is used within OUT, 194218334Speter or if OUT is an earlyclobber and IN appears elsewhere in the insn. */ 194318334Speter if (hard_regs_live_known 194418334Speter && GET_CODE (in) == REG 194518334Speter && REGNO (in) < FIRST_PSEUDO_REGISTER 1946132718Skan && (value == 0 194718334Speter || find_reg_note (this_insn, REG_UNUSED, real_out)) 194890075Sobrien && find_reg_note (this_insn, REG_DEAD, real_in) 194990075Sobrien && !fixed_regs[REGNO (in)] 195090075Sobrien && HARD_REGNO_MODE_OK (REGNO (in), 195190075Sobrien /* The only case where out and real_out might 1952169689Skan have different modes is where real_out 195390075Sobrien is a subreg, and in that case, out 195418334Speter has a real mode. */ 1955169689Skan (GET_MODE (out) != VOIDmode 1956169689Skan ? GET_MODE (out) : outmode))) 195718334Speter { 1958215840Sdim unsigned int regno = REGNO (in) + in_offset; 1959215840Sdim unsigned int nwords = HARD_REGNO_NREGS (regno, inmode); 1960215840Sdim 1961215840Sdim if (! refers_to_regno_for_reload_p (regno, regno + nwords, out, (rtx*) 0) 196218334Speter && ! hard_reg_set_here_p (regno, regno + nwords, 196318334Speter PATTERN (this_insn)) 196418334Speter && (! earlyclobber 196518334Speter || ! refers_to_regno_for_reload_p (regno, regno + nwords, 196618334Speter PATTERN (this_insn), inloc))) 196718334Speter { 1968132718Skan unsigned int i; 196918334Speter 197050397Sobrien for (i = 0; i < nwords; i++) 197150397Sobrien if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], 197218334Speter regno + i)) 197350397Sobrien break; 1974169689Skan 197518334Speter if (i == nwords) 197618334Speter { 197718334Speter /* If we were going to use OUT as the reload reg 197818334Speter and changed our mind, it means OUT is a dummy that 197918334Speter dies here. So don't bother copying value to it. */ 198018334Speter if (for_real >= 0 && value == real_out) 1981132718Skan rld[for_real].out = 0; 198218334Speter if (GET_CODE (real_in) == REG) 198350397Sobrien value = real_in; 198418334Speter else 198518334Speter value = gen_rtx_REG (inmode, regno); 1986169689Skan } 1987132718Skan } 1988132718Skan } 1989132718Skan 1990169689Skan return value; 1991169689Skan} 1992169689Skan 1993169689Skan/* This page contains subroutines used mainly for determining 1994169689Skan whether the IN or an OUT of a reload can serve as the 1995169689Skan reload register. */ 1996169689Skan 1997169689Skan/* Return 1 if X is an operand of an insn that is being earlyclobbered. */ 1998132718Skan 1999169689Skanint 2000169689Skanearlyclobber_operand_p (x) 2001169689Skan rtx x; 2002169689Skan{ 2003169689Skan int i; 2004169689Skan 2005169689Skan for (i = 0; i < n_earlyclobbers; i++) 2006169689Skan if (reload_earlyclobbers[i] == x) 2007169689Skan return 1; 2008169689Skan 2009169689Skan return 0; 2010169689Skan} 2011169689Skan 2012169689Skan/* Return 1 if expression X alters a hard reg in the range 2013169689Skan from BEG_REGNO (inclusive) to END_REGNO (exclusive), 2014169689Skan either explicitly or in the guise of a pseudo-reg allocated to REGNO. 2015169689Skan X should be the body of an instruction. */ 2016169689Skan 2017169689Skanstatic int 2018169689Skanhard_reg_set_here_p (beg_regno, end_regno, x) 2019169689Skan unsigned int beg_regno, end_regno; 2020132718Skan rtx x; 2021132718Skan{ 2022169689Skan if (GET_CODE (x) == SET || GET_CODE (x) == CLOBBER) 2023169689Skan { 2024169689Skan rtx op0 = SET_DEST (x); 2025169689Skan 2026169689Skan while (GET_CODE (op0) == SUBREG) 2027169689Skan op0 = SUBREG_REG (op0); 2028169689Skan if (GET_CODE (op0) == REG) 2029169689Skan { 2030169689Skan unsigned int r = REGNO (op0); 2031169689Skan 2032169689Skan /* See if this reg overlaps range under consideration. */ 2033169689Skan if (r < end_regno 2034169689Skan && r + HARD_REGNO_NREGS (r, GET_MODE (op0)) > beg_regno) 2035169689Skan return 1; 2036169689Skan } 2037169689Skan } 2038169689Skan else if (GET_CODE (x) == PARALLEL) 2039169689Skan { 2040169689Skan int i = XVECLEN (x, 0) - 1; 2041132718Skan 2042169689Skan for (; i >= 0; i--) 2043169689Skan if (hard_reg_set_here_p (beg_regno, end_regno, XVECEXP (x, 0, i))) 2044132718Skan return 1; 2045132718Skan } 2046169689Skan 2047169689Skan return 0; 2048169689Skan} 2049169689Skan 205018334Speter/* Return 1 if ADDR is a valid memory address for mode MODE, 205118334Speter and check that each pseudo reg has the proper kind of 2052169689Skan hard reg. */ 2053169689Skan 2054169689Skanint 2055169689Skanstrict_memory_address_p (mode, addr) 2056169689Skan enum machine_mode mode ATTRIBUTE_UNUSED; 2057169689Skan rtx addr; 2058169689Skan{ 2059169689Skan GO_IF_LEGITIMATE_ADDRESS (mode, addr, win); 2060169689Skan return 0; 2061169689Skan 2062169689Skan win: 2063169689Skan return 1; 2064169689Skan} 2065169689Skan 2066132718Skan/* Like rtx_equal_p except that it allows a REG and a SUBREG to match 206718334Speter if they are the same hard reg, and has special hacks for 206890075Sobrien autoincrement and autodecrement. 206950397Sobrien This is specifically intended for find_reloads to use 207018334Speter in determining whether two operands match. 2071169689Skan X is the operand whose number is the lower of the two. 207218334Speter 207350397Sobrien The value is 2 if Y contains a pre-increment that matches 207450397Sobrien a non-incrementing address in X. */ 2075169689Skan 2076169689Skan/* ??? To be completely correct, we should arrange to pass 207718334Speter for X the output operand and for Y the input operand. 2078169689Skan For now, we assume that the output operand has the lower number 2079169689Skan because that is natural in (SET output (... input ...)). */ 2080169689Skan 2081169689Skanint 2082169689Skanoperands_match_p (x, y) 2083169689Skan rtx x, y; 2084169689Skan{ 2085169689Skan int i; 208618334Speter RTX_CODE code = GET_CODE (x); 208718334Speter const char *fmt; 208818334Speter int success_2; 208918334Speter 209018334Speter if (x == y) 209118334Speter return 1; 2092132718Skan if ((code == REG || (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG)) 209318334Speter && (GET_CODE (y) == REG || (GET_CODE (y) == SUBREG 209418334Speter && GET_CODE (SUBREG_REG (y)) == REG))) 209590075Sobrien { 209618334Speter int j; 209718334Speter 209818334Speter if (code == SUBREG) 209918334Speter { 210090075Sobrien i = REGNO (SUBREG_REG (x)); 210118334Speter if (i >= FIRST_PSEUDO_REGISTER) 210250397Sobrien goto slow; 2103132718Skan i += subreg_regno_offset (REGNO (SUBREG_REG (x)), 210418334Speter GET_MODE (SUBREG_REG (x)), 210550397Sobrien SUBREG_BYTE (x), 210650397Sobrien GET_MODE (x)); 210750397Sobrien } 210850397Sobrien else 210918334Speter i = REGNO (x); 211050397Sobrien 211118334Speter if (GET_CODE (y) == SUBREG) 211250397Sobrien { 211350397Sobrien j = REGNO (SUBREG_REG (y)); 211450397Sobrien if (j >= FIRST_PSEUDO_REGISTER) 211590075Sobrien goto slow; 2116132718Skan j += subreg_regno_offset (REGNO (SUBREG_REG (y)), 211752284Sobrien GET_MODE (SUBREG_REG (y)), 211852284Sobrien SUBREG_BYTE (y), 211952284Sobrien GET_MODE (y)); 212050397Sobrien } 212150397Sobrien else 212218334Speter j = REGNO (y); 212350397Sobrien 212418334Speter /* On a WORDS_BIG_ENDIAN machine, point to the last register of a 212518334Speter multiple hard register group, so that for example (reg:DI 0) and 212618334Speter (reg:SI 1) will be considered the same register. */ 212718334Speter if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (x)) > UNITS_PER_WORD 212818334Speter && i < FIRST_PSEUDO_REGISTER) 212918334Speter i += (GET_MODE_SIZE (GET_MODE (x)) / UNITS_PER_WORD) - 1; 213018334Speter if (WORDS_BIG_ENDIAN && GET_MODE_SIZE (GET_MODE (y)) > UNITS_PER_WORD 2131169689Skan && j < FIRST_PSEUDO_REGISTER) 2132169689Skan j += (GET_MODE_SIZE (GET_MODE (y)) / UNITS_PER_WORD) - 1; 213348743Sobrien 213418334Speter return i == j; 2135132718Skan } 213618334Speter /* If two operands must match, because they are really a single 213718334Speter operand of an assembler insn, then two postincrements are invalid 213890075Sobrien because the assembler insn would increment only once. 213918334Speter On the other hand, an postincrement matches ordinary indexing 2140132718Skan if the postincrement is the output operand. */ 214118334Speter if (code == POST_DEC || code == POST_INC || code == POST_MODIFY) 2142169689Skan return operands_match_p (XEXP (x, 0), y); 2143169689Skan /* Two preincrements are invalid 2144169689Skan because the assembler insn would increment only once. 214518334Speter On the other hand, an preincrement matches ordinary indexing 214618334Speter if the preincrement is the input operand. 214718334Speter In this case, return 2, since some callers need to do special 2148169689Skan things when this happens. */ 214918334Speter if (GET_CODE (y) == PRE_DEC || GET_CODE (y) == PRE_INC 2150169689Skan || GET_CODE (y) == PRE_MODIFY) 215118334Speter return operands_match_p (x, XEXP (y, 0)) ? 2 : 0; 215218334Speter 215318334Speter slow: 215450397Sobrien 215518334Speter /* Now we have disposed of all the cases 215690075Sobrien in which different rtx codes can match. */ 215790075Sobrien if (code != GET_CODE (y)) 215890075Sobrien return 0; 215918334Speter if (code == LABEL_REF) 2160169689Skan return XEXP (x, 0) == XEXP (y, 0); 216118334Speter if (code == SYMBOL_REF) 216218334Speter return XSTR (x, 0) == XSTR (y, 0); 216318334Speter 216418334Speter /* (MULT:SI x y) and (MULT:HI x y) are NOT equivalent. */ 216590075Sobrien 2166132718Skan if (GET_MODE (x) != GET_MODE (y)) 2167132718Skan return 0; 2168132718Skan 2169169689Skan /* Compare the elements. If any pair of corresponding elements 2170169689Skan fail to match, return 0 for the whole things. */ 2171169689Skan 2172169689Skan success_2 = 0; 217318334Speter fmt = GET_RTX_FORMAT (code); 217448743Sobrien for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 217518334Speter { 217690075Sobrien int val, j; 217790075Sobrien switch (fmt[i]) 217818334Speter { 217990075Sobrien case 'w': 2180132718Skan if (XWINT (x, i) != XWINT (y, i)) 218190075Sobrien return 0; 218290075Sobrien break; 218390075Sobrien 218418334Speter case 'i': 218590075Sobrien if (XINT (x, i) != XINT (y, i)) 218690075Sobrien return 0; 218790075Sobrien break; 218890075Sobrien 218990075Sobrien case 'e': 219090075Sobrien val = operands_match_p (XEXP (x, i), XEXP (y, i)); 219190075Sobrien if (val == 0) 219290075Sobrien return 0; 219390075Sobrien /* If any subexpression returns 2, 2194132718Skan we should return 2 if we are successful. */ 219518334Speter if (val == 2) 219690075Sobrien success_2 = 1; 219718334Speter break; 219890075Sobrien 219990075Sobrien case '0': 220090075Sobrien break; 220190075Sobrien 220290075Sobrien case 'E': 220318334Speter if (XVECLEN (x, i) != XVECLEN (y, i)) 220418334Speter return 0; 220518334Speter for (j = XVECLEN (x, i) - 1; j >= 0; --j) 220690075Sobrien { 220718334Speter val = operands_match_p (XVECEXP (x, i, j), XVECEXP (y, i, j)); 220890075Sobrien if (val == 0) 220918334Speter return 0; 221090075Sobrien if (val == 2) 221118334Speter success_2 = 1; 221290075Sobrien } 221318334Speter break; 221490075Sobrien 221590075Sobrien /* It is believed that rtx's at this level will never 221690075Sobrien contain anything but integers and other rtx's, 221718334Speter except for within LABEL_REFs and SYMBOL_REFs. */ 221890075Sobrien default: 221918334Speter abort (); 222090075Sobrien } 222190075Sobrien } 222218334Speter return 1 + success_2; 222390075Sobrien} 2224132718Skan 222590075Sobrien/* Describe the range of registers or memory referenced by X. 222690075Sobrien If X is a register, set REG_FLAG and put the first register 222790075Sobrien number into START and the last plus one into END. 222890075Sobrien If X is a memory reference, put a base address into BASE 222990075Sobrien and a range of integer offsets into START and END. 223018334Speter If X is pushing on the stack, we can assume it causes no trouble, 223190075Sobrien so we set the SAFE field. */ 223218334Speter 223390075Sobrienstatic struct decomposition 2234132718Skandecompose (x) 2235132718Skan rtx x; 2236132718Skan{ 223790075Sobrien struct decomposition val; 223890075Sobrien int all_const = 0; 2239169689Skan 2240169689Skan val.reg_flag = 0; 2241169689Skan val.safe = 0; 2242169689Skan val.base = 0; 224390075Sobrien if (GET_CODE (x) == MEM) 224490075Sobrien { 224590075Sobrien rtx base = NULL_RTX, offset = 0; 224690075Sobrien rtx addr = XEXP (x, 0); 224790075Sobrien 2248169689Skan if (GET_CODE (addr) == PRE_DEC || GET_CODE (addr) == PRE_INC 2249169689Skan || GET_CODE (addr) == POST_DEC || GET_CODE (addr) == POST_INC) 225090075Sobrien { 225190075Sobrien val.base = XEXP (addr, 0); 2252132718Skan val.start = -GET_MODE_SIZE (GET_MODE (x)); 225390075Sobrien val.end = GET_MODE_SIZE (GET_MODE (x)); 225490075Sobrien val.safe = REGNO (val.base) == STACK_POINTER_REGNUM; 225590075Sobrien return val; 225690075Sobrien } 225790075Sobrien 225890075Sobrien if (GET_CODE (addr) == PRE_MODIFY || GET_CODE (addr) == POST_MODIFY) 2259169689Skan { 226090075Sobrien if (GET_CODE (XEXP (addr, 1)) == PLUS 226190075Sobrien && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0) 226290075Sobrien && CONSTANT_P (XEXP (XEXP (addr, 1), 1))) 226390075Sobrien { 226490075Sobrien val.base = XEXP (addr, 0); 226518334Speter val.start = -INTVAL (XEXP (XEXP (addr, 1), 1)); 226690075Sobrien val.end = INTVAL (XEXP (XEXP (addr, 1), 1)); 226790075Sobrien val.safe = REGNO (val.base) == STACK_POINTER_REGNUM; 226890075Sobrien return val; 226918334Speter } 227090075Sobrien } 227190075Sobrien 227290075Sobrien if (GET_CODE (addr) == CONST) 227390075Sobrien { 227490075Sobrien addr = XEXP (addr, 0); 227590075Sobrien all_const = 1; 227618334Speter } 227790075Sobrien if (GET_CODE (addr) == PLUS) 227890075Sobrien { 227918334Speter if (CONSTANT_P (XEXP (addr, 0))) 228018334Speter { 228190075Sobrien base = XEXP (addr, 1); 228290075Sobrien offset = XEXP (addr, 0); 228318334Speter } 228490075Sobrien else if (CONSTANT_P (XEXP (addr, 1))) 228590075Sobrien { 2286169689Skan base = XEXP (addr, 0); 228718334Speter offset = XEXP (addr, 1); 228818334Speter } 2289169689Skan } 229018334Speter 229190075Sobrien if (offset == 0) 229218334Speter { 229318334Speter base = addr; 229418334Speter offset = const0_rtx; 2295132718Skan } 229618334Speter if (GET_CODE (offset) == CONST) 2297169689Skan offset = XEXP (offset, 0); 2298132718Skan if (GET_CODE (offset) == PLUS) 2299132718Skan { 230018334Speter if (GET_CODE (XEXP (offset, 0)) == CONST_INT) 2301132718Skan { 2302132718Skan base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 1)); 2303132718Skan offset = XEXP (offset, 0); 2304132718Skan } 2305132718Skan else if (GET_CODE (XEXP (offset, 1)) == CONST_INT) 2306132718Skan { 2307132718Skan base = gen_rtx_PLUS (GET_MODE (base), base, XEXP (offset, 0)); 230818334Speter offset = XEXP (offset, 1); 2309132718Skan } 2310132718Skan else 2311132718Skan { 231218334Speter base = gen_rtx_PLUS (GET_MODE (base), base, offset); 2313132718Skan offset = const0_rtx; 2314132718Skan } 2315132718Skan } 2316132718Skan else if (GET_CODE (offset) != CONST_INT) 231718334Speter { 2318132718Skan base = gen_rtx_PLUS (GET_MODE (base), base, offset); 2319132718Skan offset = const0_rtx; 2320132718Skan } 2321132718Skan 2322132718Skan if (all_const && GET_CODE (base) == PLUS) 2323132718Skan base = gen_rtx_CONST (GET_MODE (base), base); 2324132718Skan 2325132718Skan if (GET_CODE (offset) != CONST_INT) 2326132718Skan abort (); 2327132718Skan 2328132718Skan val.start = INTVAL (offset); 2329132718Skan val.end = val.start + GET_MODE_SIZE (GET_MODE (x)); 2330132718Skan val.base = base; 233118334Speter return val; 233218334Speter } 233318334Speter else if (GET_CODE (x) == REG) 233418334Speter { 233518334Speter val.reg_flag = 1; 233618334Speter val.start = true_regnum (x); 2337169689Skan if (val.start < 0) 233818334Speter { 2339117395Skan /* A pseudo with no hard reg. */ 234018334Speter val.start = REGNO (x); 234118334Speter val.end = val.start + 1; 234218334Speter } 234318334Speter else 234418334Speter /* A hard reg. */ 234518334Speter val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x)); 2346132718Skan } 234718334Speter else if (GET_CODE (x) == SUBREG) 234890075Sobrien { 234990075Sobrien if (GET_CODE (SUBREG_REG (x)) != REG) 235090075Sobrien /* This could be more precise, but it's good enough. */ 235118334Speter return decompose (SUBREG_REG (x)); 235218334Speter val.reg_flag = 1; 235318334Speter val.start = true_regnum (x); 235418334Speter if (val.start < 0) 235590075Sobrien return decompose (SUBREG_REG (x)); 235690075Sobrien else 235718334Speter /* A hard reg. */ 235890075Sobrien val.end = val.start + HARD_REGNO_NREGS (val.start, GET_MODE (x)); 235918334Speter } 236018334Speter else if (CONSTANT_P (x) 236190075Sobrien /* This hasn't been assigned yet, so it can't conflict yet. */ 236290075Sobrien || GET_CODE (x) == SCRATCH) 236318334Speter val.safe = 1; 236490075Sobrien else 236590075Sobrien abort (); 236618334Speter return val; 236718334Speter} 236818334Speter 236918334Speter/* Return 1 if altering Y will not modify the value of X. 237018334Speter Y is also described by YDATA, which should be decompose (Y). */ 237118334Speter 237218334Speterstatic int 237318334Speterimmune_p (x, y, ydata) 237418334Speter rtx x, y; 237518334Speter struct decomposition ydata; 237618334Speter{ 237718334Speter struct decomposition xdata; 237818334Speter 237918334Speter if (ydata.reg_flag) 238050397Sobrien return !refers_to_regno_for_reload_p (ydata.start, ydata.end, x, (rtx*) 0); 2381169689Skan if (ydata.safe) 238218334Speter return 1; 238318334Speter 238418334Speter if (GET_CODE (y) != MEM) 238518334Speter abort (); 238618334Speter /* If Y is memory and X is not, Y can't affect X. */ 238718334Speter if (GET_CODE (x) != MEM) 238850397Sobrien return 1; 238990075Sobrien 239018334Speter xdata = decompose (x); 239118334Speter 239218334Speter if (! rtx_equal_p (xdata.base, ydata.base)) 2393169689Skan { 239418334Speter /* If bases are distinct symbolic constants, there is no overlap. */ 239518334Speter if (CONSTANT_P (xdata.base) && CONSTANT_P (ydata.base)) 2396169689Skan return 1; 239750397Sobrien /* Constants and stack slots never overlap. */ 239818334Speter if (CONSTANT_P (xdata.base) 239918334Speter && (ydata.base == frame_pointer_rtx 240018334Speter || ydata.base == hard_frame_pointer_rtx 240118334Speter || ydata.base == stack_pointer_rtx)) 240218334Speter return 1; 240318334Speter if (CONSTANT_P (ydata.base) 240418334Speter && (xdata.base == frame_pointer_rtx 2405132718Skan || xdata.base == hard_frame_pointer_rtx 240618334Speter || xdata.base == stack_pointer_rtx)) 2407117395Skan return 1; 2408117395Skan /* If either base is variable, we don't know anything. */ 2409117395Skan return 0; 241090075Sobrien } 2411117395Skan 2412117395Skan return (xdata.start >= ydata.end || ydata.start >= xdata.end); 2413117395Skan} 2414169689Skan 2415169689Skan/* Similar, but calls decompose. */ 2416169689Skan 2417169689Skanint 2418169689Skansafe_from_earlyclobber (op, clobber) 241918334Speter rtx op, clobber; 242018334Speter{ 2421132718Skan struct decomposition early_data; 2422132718Skan 242318334Speter early_data = decompose (clobber); 2424132718Skan return immune_p (op, clobber, early_data); 2425132718Skan} 242690075Sobrien 2427132718Skan/* Main entry point of this file: search the body of INSN 242890075Sobrien for values that need reloading and record them with push_reload. 242990075Sobrien REPLACE nonzero means record also where the values occur 2430132718Skan so that subst_reloads can be used. 243190075Sobrien 2432169689Skan IND_LEVELS says how many levels of indirection are supported by this 243390075Sobrien machine; a value of zero means that a memory reference is not a valid 243490075Sobrien memory address. 2435132718Skan 2436132718Skan LIVE_KNOWN says we have valid information about which hard 243790075Sobrien regs are live at each point in the program; this is true when 243890075Sobrien we are called from global_alloc but false when stupid register 2439132718Skan allocation has been done. 2440117395Skan 244190075Sobrien RELOAD_REG_P if nonzero is a vector indexed by hard reg number 244218334Speter which is nonnegative if the reg has been commandeered for reloading into. 244350397Sobrien It is copied into STATIC_RELOAD_REG_P and referenced from there 244450397Sobrien by various subroutines. 244550397Sobrien 244650397Sobrien Return TRUE if some operands need to be changed, because of swapping 244718334Speter commutative operands, reg_equiv_address substitution, or whatever. */ 244850397Sobrien 244990075Sobrienint 245090075Sobrienfind_reloads (insn, replace, ind_levels, live_known, reload_reg_p) 245150397Sobrien rtx insn; 245250397Sobrien int replace, ind_levels; 245350397Sobrien int live_known; 2454117395Skan short *reload_reg_p; 245518334Speter{ 245650397Sobrien int insn_code_number; 2457169689Skan int i, j; 2458169689Skan int noperands; 245950397Sobrien /* These start out as the constraints for the insn 246018334Speter and they are chewed up as we consider alternatives. */ 246150397Sobrien char *constraints[MAX_RECOG_OPERANDS]; 2462117395Skan /* These are the preferred classes for an operand, or NO_REGS if it isn't 2463117395Skan a register. */ 246418334Speter enum reg_class preferred_class[MAX_RECOG_OPERANDS]; 246550397Sobrien char pref_or_nothing[MAX_RECOG_OPERANDS]; 2466169689Skan /* Nonzero for a MEM operand whose entire address needs a reload. */ 2467169689Skan int address_reloaded[MAX_RECOG_OPERANDS]; 2468169689Skan /* Value of enum reload_type to use for operand. */ 246990075Sobrien enum reload_type operand_type[MAX_RECOG_OPERANDS]; 2470169689Skan /* Value of enum reload_type to use within address of operand. */ 247118334Speter enum reload_type address_type[MAX_RECOG_OPERANDS]; 2472169689Skan /* Save the usage of each operand. */ 2473169689Skan enum reload_usage { RELOAD_READ, RELOAD_READ_WRITE, RELOAD_WRITE } modified[MAX_RECOG_OPERANDS]; 2474169689Skan int no_input_reloads = 0, no_output_reloads = 0; 247550397Sobrien int n_alternatives; 2476169689Skan int this_alternative[MAX_RECOG_OPERANDS]; 2477169689Skan char this_alternative_match_win[MAX_RECOG_OPERANDS]; 247850397Sobrien char this_alternative_win[MAX_RECOG_OPERANDS]; 247950397Sobrien char this_alternative_offmemok[MAX_RECOG_OPERANDS]; 2480102780Skan char this_alternative_earlyclobber[MAX_RECOG_OPERANDS]; 248150397Sobrien int this_alternative_matches[MAX_RECOG_OPERANDS]; 248250397Sobrien int swapped; 248350397Sobrien int goal_alternative[MAX_RECOG_OPERANDS]; 248450397Sobrien int this_alternative_number; 2485169689Skan int goal_alternative_number = 0; 248650397Sobrien int operand_reloadnum[MAX_RECOG_OPERANDS]; 2487169689Skan int goal_alternative_matches[MAX_RECOG_OPERANDS]; 248850397Sobrien int goal_alternative_matched[MAX_RECOG_OPERANDS]; 248950397Sobrien char goal_alternative_match_win[MAX_RECOG_OPERANDS]; 249050397Sobrien char goal_alternative_win[MAX_RECOG_OPERANDS]; 249150397Sobrien char goal_alternative_offmemok[MAX_RECOG_OPERANDS]; 249250397Sobrien char goal_alternative_earlyclobber[MAX_RECOG_OPERANDS]; 249350397Sobrien int goal_alternative_swapped; 2494169689Skan int best; 2495169689Skan int commutative; 2496169689Skan char operands_match[MAX_RECOG_OPERANDS][MAX_RECOG_OPERANDS]; 2497169689Skan rtx substed_operand[MAX_RECOG_OPERANDS]; 2498169689Skan rtx body = PATTERN (insn); 2499169689Skan rtx set = single_set (insn); 2500169689Skan int goal_earlyclobber = 0, this_earlyclobber; 2501169689Skan enum machine_mode operand_mode[MAX_RECOG_OPERANDS]; 250250397Sobrien int retval = 0; 250350397Sobrien 250418334Speter this_insn = insn; 250550397Sobrien n_reloads = 0; 250650397Sobrien n_replacements = 0; 250750397Sobrien n_earlyclobbers = 0; 2508117395Skan replace_reloads = replace; 2509117395Skan hard_regs_live_known = live_known; 251050397Sobrien static_reload_reg_p = reload_reg_p; 251150397Sobrien 251250397Sobrien /* JUMP_INSNs and CALL_INSNs are not allowed to have any output reloads; 251350397Sobrien neither are insns that SET cc0. Insns that use CC0 are not allowed 2514117395Skan to have any input reloads. */ 251590075Sobrien if (GET_CODE (insn) == JUMP_INSN || GET_CODE (insn) == CALL_INSN) 251650397Sobrien no_output_reloads = 1; 251790075Sobrien 2518117395Skan#ifdef HAVE_cc0 251918334Speter if (reg_referenced_p (cc0_rtx, PATTERN (insn))) 252018334Speter no_input_reloads = 1; 2521132718Skan if (reg_set_p (cc0_rtx, PATTERN (insn))) 252218334Speter no_output_reloads = 1; 252318334Speter#endif 252450397Sobrien 252518334Speter#ifdef SECONDARY_MEMORY_NEEDED 252618334Speter /* The eliminated forms of any secondary memory locations are per-insn, so 252718334Speter clear them out here. */ 252818334Speter 2529132718Skan memset ((char *) secondary_memlocs_elim, 0, sizeof secondary_memlocs_elim); 2530132718Skan#endif 2531132718Skan 2532132718Skan /* Dispose quickly of (set (reg..) (reg..)) if both have hard regs and it 2533169689Skan is cheap to move between them. If it is not, there may not be an insn 2534169689Skan to do the copy, so we may need a reload. */ 2535169689Skan if (GET_CODE (body) == SET 2536169689Skan && GET_CODE (SET_DEST (body)) == REG 2537169689Skan && REGNO (SET_DEST (body)) < FIRST_PSEUDO_REGISTER 2538132718Skan && GET_CODE (SET_SRC (body)) == REG 2539132718Skan && REGNO (SET_SRC (body)) < FIRST_PSEUDO_REGISTER 2540117395Skan && REGISTER_MOVE_COST (GET_MODE (SET_SRC (body)), 2541117395Skan REGNO_REG_CLASS (REGNO (SET_SRC (body))), 2542117395Skan REGNO_REG_CLASS (REGNO (SET_DEST (body)))) == 2) 254318334Speter return 0; 2544132718Skan 254518334Speter extract_insn (insn); 2546117395Skan 254718334Speter noperands = reload_n_operands = recog_data.n_operands; 2548117395Skan n_alternatives = recog_data.n_alternatives; 2549117395Skan 2550117395Skan /* Just return "no reloads" if insn has no operands with constraints. */ 2551117395Skan if (noperands == 0 || n_alternatives == 0) 255218334Speter return 0; 2553117395Skan 255418334Speter insn_code_number = INSN_CODE (insn); 255518334Speter this_insn_is_asm = insn_code_number < 0; 2556117395Skan 255718334Speter memcpy (operand_mode, recog_data.operand_mode, 255850397Sobrien noperands * sizeof (enum machine_mode)); 255918334Speter memcpy (constraints, recog_data.constraints, noperands * sizeof (char *)); 2560117395Skan 256118334Speter commutative = -1; 2562169689Skan 2563169689Skan /* If we will need to know, later, whether some pair of operands 2564117395Skan are the same, we must compare them now and save the result. 256550397Sobrien Reloading the base and index registers will clobber them 256650397Sobrien and afterward they will fail to match. */ 256718334Speter 2568117395Skan for (i = 0; i < noperands; i++) 256918334Speter { 257050397Sobrien char *p; 2571117395Skan int c; 257250397Sobrien 257350397Sobrien substed_operand[i] = recog_data.operand[i]; 2574117395Skan p = constraints[i]; 257550397Sobrien 257650397Sobrien modified[i] = RELOAD_READ; 2577117395Skan 2578117395Skan /* Scan this operand's constraint to see if it is an output operand, 2579117395Skan an in-out operand, is commutative, or should match another. */ 258050397Sobrien 2581117395Skan while ((c = *p++)) 2582117395Skan { 2583117395Skan if (c == '=') 258450397Sobrien modified[i] = RELOAD_WRITE; 2585117395Skan else if (c == '+') 2586169689Skan modified[i] = RELOAD_READ_WRITE; 2587169689Skan else if (c == '%') 2588169689Skan { 258918334Speter /* The last operand should not be marked commutative. */ 2590169689Skan if (i == noperands - 1) 2591169689Skan abort (); 2592169689Skan 259350397Sobrien commutative = i; 2594169689Skan } 2595169689Skan else if (ISDIGIT (c)) 2596169689Skan { 2597169689Skan c = strtoul (p - 1, &p, 10); 2598169689Skan 2599169689Skan operands_match[c][i] 2600169689Skan = operands_match_p (recog_data.operand[c], 2601169689Skan recog_data.operand[i]); 2602169689Skan 2603169689Skan /* An operand may not match itself. */ 2604169689Skan if (c == i) 2605169689Skan abort (); 2606169689Skan 2607169689Skan /* If C can be commuted with C+1, and C might need to match I, 2608169689Skan then C+1 might also need to match I. */ 2609169689Skan if (commutative >= 0) 261050397Sobrien { 2611169689Skan if (c == commutative || c == commutative + 1) 2612169689Skan { 2613169689Skan int other = c + (c == commutative ? 1 : -1); 2614169689Skan operands_match[other][i] 2615117395Skan = operands_match_p (recog_data.operand[other], 2616117395Skan recog_data.operand[i]); 2617169689Skan } 2618169689Skan if (i == commutative || i == commutative + 1) 2619169689Skan { 2620169689Skan int other = i + (i == commutative ? 1 : -1); 262118334Speter operands_match[c][other] 2622169689Skan = operands_match_p (recog_data.operand[c], 2623169689Skan recog_data.operand[other]); 2624169689Skan } 2625169689Skan /* Note that C is supposed to be less than I. 2626169689Skan No need to consider altering both C and I because in 2627169689Skan that case we would alter one into the other. */ 2628169689Skan } 2629169689Skan } 2630169689Skan } 2631169689Skan } 2632169689Skan 2633169689Skan /* Examine each operand that is a memory reference or memory address 2634169689Skan and reload parts of the addresses into index registers. 2635169689Skan Also here any references to pseudo regs that didn't get hard regs 2636169689Skan but are equivalent to constants get replaced in the insn itself 263750397Sobrien with those constants. Nobody will ever see them again. 2638169689Skan 2639169689Skan Finally, set up the preferred classes of each operand. */ 264050397Sobrien 264150397Sobrien for (i = 0; i < noperands; i++) 2642102780Skan { 264350397Sobrien RTX_CODE code = GET_CODE (recog_data.operand[i]); 2644117395Skan 264550397Sobrien address_reloaded[i] = 0; 2646117395Skan operand_type[i] = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT 2647117395Skan : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT 2648117395Skan : RELOAD_OTHER); 2649117395Skan address_type[i] 265050397Sobrien = (modified[i] == RELOAD_READ ? RELOAD_FOR_INPUT_ADDRESS 265150397Sobrien : modified[i] == RELOAD_WRITE ? RELOAD_FOR_OUTPUT_ADDRESS 265250397Sobrien : RELOAD_OTHER); 265350397Sobrien 265452284Sobrien if (*constraints[i] == 0) 2655117395Skan /* Ignore things like match_operator operands. */ 2656117395Skan ; 265750397Sobrien else if (constraints[i][0] == 'p') 265850397Sobrien { 265950397Sobrien find_reloads_address (recog_data.operand_mode[i], (rtx*) 0, 266050397Sobrien recog_data.operand[i], 2661169689Skan recog_data.operand_loc[i], 2662117395Skan i, operand_type[i], ind_levels, insn); 266350397Sobrien 266450397Sobrien /* If we now have a simple operand where we used to have a 266590075Sobrien PLUS or MULT, re-recognize and try again. */ 2666117395Skan if ((GET_RTX_CLASS (GET_CODE (*recog_data.operand_loc[i])) == 'o' 2667169689Skan || GET_CODE (*recog_data.operand_loc[i]) == SUBREG) 2668169689Skan && (GET_CODE (recog_data.operand[i]) == MULT 2669117395Skan || GET_CODE (recog_data.operand[i]) == PLUS)) 2670117395Skan { 267190075Sobrien INSN_CODE (insn) = -1; 267290075Sobrien retval = find_reloads (insn, replace, ind_levels, live_known, 267390075Sobrien reload_reg_p); 267418334Speter return retval; 267518334Speter } 2676169689Skan 267718334Speter recog_data.operand[i] = *recog_data.operand_loc[i]; 267818334Speter substed_operand[i] = recog_data.operand[i]; 2679117395Skan } 2680169689Skan else if (code == MEM) 268118334Speter { 268218334Speter address_reloaded[i] 2683132718Skan = find_reloads_address (GET_MODE (recog_data.operand[i]), 268418334Speter recog_data.operand_loc[i], 268518334Speter XEXP (recog_data.operand[i], 0), 268618334Speter &XEXP (recog_data.operand[i], 0), 268718334Speter i, address_type[i], ind_levels, insn); 268818334Speter recog_data.operand[i] = *recog_data.operand_loc[i]; 268918334Speter substed_operand[i] = recog_data.operand[i]; 2690169689Skan } 269118334Speter else if (code == SUBREG) 269218334Speter { 269318334Speter rtx reg = SUBREG_REG (recog_data.operand[i]); 269418334Speter rtx op 269518334Speter = find_reloads_toplev (recog_data.operand[i], i, address_type[i], 269618334Speter ind_levels, 269718334Speter set != 0 2698169689Skan && &SET_DEST (set) == recog_data.operand_loc[i], 269918334Speter insn, 270018334Speter &address_reloaded[i]); 270118334Speter 270250397Sobrien /* If we made a MEM to load (a part of) the stackslot of a pseudo 270350397Sobrien that didn't get a hard register, emit a USE with a REG_EQUAL 270418334Speter note in front so that we might inherit a previous, possibly 270518334Speter wider reload. */ 270618334Speter 270718334Speter if (replace 2708169689Skan && GET_CODE (op) == MEM 2709169689Skan && GET_CODE (reg) == REG 2710169689Skan && (GET_MODE_SIZE (GET_MODE (reg)) 271118334Speter >= GET_MODE_SIZE (GET_MODE (op)))) 271218334Speter set_unique_reg_note (emit_insn_before (gen_rtx_USE (VOIDmode, reg), 271318334Speter insn), 271450397Sobrien REG_EQUAL, reg_equiv_memory_loc[REGNO (reg)]); 2715132718Skan 271618334Speter substed_operand[i] = recog_data.operand[i] = op; 271718334Speter } 271818334Speter else if (code == PLUS || GET_RTX_CLASS (code) == '1') 271918334Speter /* We can get a PLUS as an "operand" as a result of register 272018334Speter elimination. See eliminate_regs and gen_reload. We handle 272118334Speter a unary operator by reloading the operand. */ 2722169689Skan substed_operand[i] = recog_data.operand[i] 2723169689Skan = find_reloads_toplev (recog_data.operand[i], i, address_type[i], 2724169689Skan ind_levels, 0, insn, 272518334Speter &address_reloaded[i]); 2726169689Skan else if (code == REG) 2727169689Skan { 2728169689Skan /* This is equivalent to calling find_reloads_toplev. 2729169689Skan The code is duplicated for speed. 2730169689Skan When we find a pseudo always equivalent to a constant, 2731169689Skan we replace it by the constant. We must be sure, however, 2732169689Skan that we don't try to replace it in the insn in which it 2733169689Skan is being set. */ 2734169689Skan int regno = REGNO (recog_data.operand[i]); 273518334Speter if (reg_equiv_constant[regno] != 0 273618334Speter && (set == 0 || &SET_DEST (set) != recog_data.operand_loc[i])) 273718334Speter { 273818334Speter /* Record the existing mode so that the check if constants are 2739117395Skan allowed will work when operand_mode isn't specified. */ 2740169689Skan 2741169689Skan if (operand_mode[i] == VOIDmode) 2742169689Skan operand_mode[i] = GET_MODE (recog_data.operand[i]); 2743169689Skan 2744117395Skan substed_operand[i] = recog_data.operand[i] 274518334Speter = reg_equiv_constant[regno]; 274618334Speter } 274718334Speter if (reg_equiv_memory_loc[regno] != 0 2748169689Skan && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)) 2749169689Skan /* We need not give a valid is_set_dest argument since the case 2750169689Skan of a constant equivalence was checked above. */ 2751169689Skan substed_operand[i] = recog_data.operand[i] 2752169689Skan = find_reloads_toplev (recog_data.operand[i], i, address_type[i], 2753169689Skan ind_levels, 0, insn, 2754169689Skan &address_reloaded[i]); 2755169689Skan } 2756169689Skan /* If the operand is still a register (we didn't replace it with an 2757169689Skan equivalent), get the preferred class to reload it into. */ 2758169689Skan code = GET_CODE (recog_data.operand[i]); 2759169689Skan preferred_class[i] 2760169689Skan = ((code == REG && REGNO (recog_data.operand[i]) 2761169689Skan >= FIRST_PSEUDO_REGISTER) 2762169689Skan ? reg_preferred_class (REGNO (recog_data.operand[i])) 2763169689Skan : NO_REGS); 2764169689Skan pref_or_nothing[i] 2765169689Skan = (code == REG 2766169689Skan && REGNO (recog_data.operand[i]) >= FIRST_PSEUDO_REGISTER 2767169689Skan && reg_alternate_class (REGNO (recog_data.operand[i])) == NO_REGS); 2768169689Skan } 2769169689Skan 2770169689Skan /* If this is simply a copy from operand 1 to operand 0, merge the 2771169689Skan preferred classes for the operands. */ 2772169689Skan if (set != 0 && noperands >= 2 && recog_data.operand[0] == SET_DEST (set) 2773169689Skan && recog_data.operand[1] == SET_SRC (set)) 2774169689Skan { 2775169689Skan preferred_class[0] = preferred_class[1] 2776169689Skan = reg_class_subunion[(int) preferred_class[0]][(int) preferred_class[1]]; 2777169689Skan pref_or_nothing[0] |= pref_or_nothing[1]; 2778169689Skan pref_or_nothing[1] |= pref_or_nothing[0]; 2779169689Skan } 2780169689Skan 2781169689Skan /* Now see what we need for pseudo-regs that didn't get hard regs 2782169689Skan or got the wrong kind of hard reg. For this, we must consider 2783169689Skan all the operands together against the register constraints. */ 2784169689Skan 2785169689Skan best = MAX_RECOG_OPERANDS * 2 + 600; 2786169689Skan 2787169689Skan swapped = 0; 2788132718Skan goal_alternative_swapped = 0; 2789132718Skan try_swapped: 2790132718Skan 2791132718Skan /* The constraints are made of several alternatives. 2792132718Skan Each operand's constraint looks like foo,bar,... with commas 2793132718Skan separating the alternatives. The first alternatives for all 279418334Speter operands go together, the second alternatives go together, etc. 2795132718Skan 2796132718Skan First loop over alternatives. */ 279718334Speter 2798132718Skan for (this_alternative_number = 0; 2799132718Skan this_alternative_number < n_alternatives; 2800132718Skan this_alternative_number++) 2801132718Skan { 2802117395Skan /* Loop over operands for one constraint alternative. */ 280318334Speter /* LOSERS counts those that don't fit this alternative 2804132718Skan and would require loading. */ 2805146895Skan int losers = 0; 2806122180Skan /* BAD is set to 1 if it some operand can't fit this alternative 2807169689Skan even after reloading. */ 2808169689Skan int bad = 0; 2809169689Skan /* REJECT is a count of how undesirable this alternative says it is 2810169689Skan if any reloading is required. If the alternative matches exactly 2811132718Skan then REJECT is ignored, but otherwise it gets this much 2812132718Skan counted against it in addition to the reloading needed. Each 2813132718Skan ? counts three times here since we want the disparaging caused by 281418334Speter a bad register class to only count 1/3 as much. */ 2815132718Skan int reject = 0; 2816169689Skan 2817169689Skan this_earlyclobber = 0; 2818169689Skan 2819169689Skan for (i = 0; i < noperands; i++) 2820169689Skan { 2821169689Skan char *p = constraints[i]; 2822169689Skan int win = 0; 2823169689Skan int did_match = 0; 2824169689Skan /* 0 => this operand can be reloaded somehow for this alternative. */ 2825169689Skan int badop = 1; 2826132718Skan /* 0 => this operand can be reloaded if the alternative allows regs. */ 282718334Speter int winreg = 0; 2828132718Skan int c; 2829132718Skan rtx operand = recog_data.operand[i]; 2830132718Skan int offset = 0; 2831132718Skan /* Nonzero means this is a MEM that must be reloaded into a reg 283218334Speter regardless of what the constraint says. */ 2833132718Skan int force_reload = 0; 2834132718Skan int offmemok = 0; 2835132718Skan /* Nonzero if a constant forced into memory would be OK for this 2836132718Skan operand. */ 2837132718Skan int constmemok = 0; 283818334Speter int earlyclobber = 0; 2839169689Skan 284090075Sobrien /* If the predicate accepts a unary operator, it means that 2841132718Skan we need to reload the operand, but do not do this for 284290075Sobrien match_operator and friends. */ 2843132718Skan if (GET_RTX_CLASS (GET_CODE (operand)) == '1' && *p != 0) 2844132718Skan operand = XEXP (operand, 0); 284590075Sobrien 2846132718Skan /* If the operand is a SUBREG, extract 2847132718Skan the REG or MEM (or maybe even a constant) within. 284818334Speter (Constants can occur as a result of reg_equiv_constant.) */ 2849132718Skan 2850132718Skan while (GET_CODE (operand) == SUBREG) 2851132718Skan { 2852132718Skan /* Offset only matters when operand is a REG and 285390075Sobrien it is a hard reg. This is because it is passed 2854132718Skan to reg_fits_class_p if it is a REG and all pseudos 2855132718Skan return 0 from that function. */ 285690075Sobrien if (GET_CODE (SUBREG_REG (operand)) == REG 2857132718Skan && REGNO (SUBREG_REG (operand)) < FIRST_PSEUDO_REGISTER) 285890075Sobrien { 2859132718Skan offset += subreg_regno_offset (REGNO (SUBREG_REG (operand)), 2860132718Skan GET_MODE (SUBREG_REG (operand)), 2861132718Skan SUBREG_BYTE (operand), 2862132718Skan GET_MODE (operand)); 2863132718Skan } 2864132718Skan operand = SUBREG_REG (operand); 286518334Speter /* Force reload if this is a constant or PLUS or if there may 2866132718Skan be a problem accessing OPERAND in the outer mode. */ 2867132718Skan if (CONSTANT_P (operand) 2868132718Skan || GET_CODE (operand) == PLUS 2869169689Skan /* We must force a reload of paradoxical SUBREGs 2870169689Skan of a MEM because the alignment of the inner value 287118334Speter may not be enough to do the outer reference. On 2872132718Skan big-endian machines, it may also reference outside 2873132718Skan the object. 287490075Sobrien 2875132718Skan On machines that extend byte operations and we have a 2876169689Skan SUBREG where both the inner and outer modes are no wider 2877132718Skan than a word and the inner mode is narrower, is integral, 287890075Sobrien and gets extended when loaded from memory, combine.c has 287918334Speter made assumptions about the behavior of the machine in such 2880132718Skan register access. If the data is, in fact, in memory we 2881132718Skan must always load using the size assumed to be in the 2882132718Skan register and let the insn do the different-sized 288390075Sobrien accesses. 2884132718Skan 2885132718Skan This is doubly true if WORD_REGISTER_OPERATIONS. In 2886132718Skan this case eliminate_regs has left non-paradoxical 2887132718Skan subregs for push_reloads to see. Make sure it does 2888132718Skan by forcing the reload. 2889132718Skan 2890132718Skan ??? When is it right at this stage to have a subreg 2891132718Skan of a mem that is _not_ to be handled specialy? IMO 289290075Sobrien those should have been reduced to just a mem. */ 2893132718Skan || ((GET_CODE (operand) == MEM 2894132718Skan || (GET_CODE (operand)== REG 289518334Speter && REGNO (operand) >= FIRST_PSEUDO_REGISTER)) 2896132718Skan#ifndef WORD_REGISTER_OPERATIONS 2897132718Skan && (((GET_MODE_BITSIZE (GET_MODE (operand)) 2898132718Skan < BIGGEST_ALIGNMENT) 289990075Sobrien && (GET_MODE_SIZE (operand_mode[i]) 2900169689Skan > GET_MODE_SIZE (GET_MODE (operand)))) 2901169689Skan || (GET_CODE (operand) == MEM && BYTES_BIG_ENDIAN) 2902169689Skan#ifdef LOAD_EXTEND_OP 2903132718Skan || (GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD 2904132718Skan && (GET_MODE_SIZE (GET_MODE (operand)) 2905132718Skan <= UNITS_PER_WORD) 2906132718Skan && (GET_MODE_SIZE (operand_mode[i]) 2907132718Skan > GET_MODE_SIZE (GET_MODE (operand))) 2908132718Skan && INTEGRAL_MODE_P (GET_MODE (operand)) 2909132718Skan && LOAD_EXTEND_OP (GET_MODE (operand)) != NIL) 2910132718Skan#endif 2911132718Skan ) 291218334Speter#endif 291318334Speter ) 2914132718Skan /* This following hunk of code should no longer be 291518334Speter needed at all with SUBREG_BYTE. If you need this 291618334Speter code back, please explain to me why so I can 2917169689Skan fix the real problem. -DaveM */ 2918169689Skan#if 0 2919169689Skan /* Subreg of a hard reg which can't handle the subreg's mode 292018334Speter or which would handle that mode in the wrong number of 292118334Speter registers for subregging to work. */ 2922169689Skan || (GET_CODE (operand) == REG 292318334Speter && REGNO (operand) < FIRST_PSEUDO_REGISTER 2924122180Skan && ((GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD 292518334Speter && (GET_MODE_SIZE (GET_MODE (operand)) 2926169689Skan > UNITS_PER_WORD) 2927132718Skan && ((GET_MODE_SIZE (GET_MODE (operand)) 2928122180Skan / UNITS_PER_WORD) 2929122180Skan != HARD_REGNO_NREGS (REGNO (operand), 2930132718Skan GET_MODE (operand)))) 2931122180Skan || ! HARD_REGNO_MODE_OK (REGNO (operand) + offset, 2932122180Skan operand_mode[i]))) 2933132718Skan#endif 2934122180Skan ) 293518334Speter force_reload = 1; 293618334Speter } 2937122180Skan 293818334Speter this_alternative[i] = (int) NO_REGS; 2939132718Skan this_alternative_win[i] = 0; 2940169689Skan this_alternative_match_win[i] = 0; 2941169689Skan this_alternative_offmemok[i] = 0; 2942169689Skan this_alternative_earlyclobber[i] = 0; 2943169689Skan this_alternative_matches[i] = -1; 2944132718Skan 2945169689Skan /* An empty constraint or empty alternative 2946169689Skan allows anything which matched the pattern. */ 2947169689Skan if (*p == 0 || *p == ',') 2948169689Skan win = 1, badop = 0; 2949169689Skan 2950169689Skan /* Scan this alternative's specs for this operand; 2951169689Skan set WIN if the operand fits any letter in this alternative. 2952169689Skan Otherwise, clear BADOP if this operand could 2953169689Skan fit some letter after reloads, 2954169689Skan or set WINREG if this operand could fit after reloads 2955169689Skan provided the constraint allows some registers. */ 2956169689Skan 2957169689Skan while (*p && (c = *p++) != ',') 2958169689Skan switch (c) 2959169689Skan { 2960169689Skan case '=': case '+': case '*': 2961169689Skan break; 2962169689Skan 2963169689Skan case '%': 2964169689Skan /* The last operand should not be marked commutative. */ 2965169689Skan if (i != noperands - 1) 2966169689Skan commutative = i; 2967169689Skan break; 2968169689Skan 2969169689Skan case '?': 2970132718Skan reject += 6; 2971132718Skan break; 2972132718Skan 2973132718Skan case '!': 2974132718Skan reject = 600; 2975132718Skan break; 2976132718Skan 2977132718Skan case '#': 2978132718Skan /* Ignore rest of this alternative as far as 2979132718Skan reloading is concerned. */ 2980132718Skan while (*p && *p != ',') 2981132718Skan p++; 2982169689Skan break; 2983169689Skan 2984132718Skan case '0': case '1': case '2': case '3': case '4': 2985132718Skan case '5': case '6': case '7': case '8': case '9': 2986132718Skan c = strtoul (p - 1, &p, 10); 298718334Speter 2988117395Skan this_alternative_matches[i] = c; 2989117395Skan /* We are supposed to match a previous operand. 2990169689Skan If we do, we win if that one did. 2991169689Skan If we do not, count both of the operands as losers. 2992169689Skan (This is too conservative, since most of the time 2993169689Skan only a single reload insn will be needed to make 2994117395Skan the two operands win. As a result, this alternative 2995169689Skan may be rejected when it is actually desirable.) */ 2996117395Skan if ((swapped && (c != commutative || i != commutative + 1)) 2997169689Skan /* If we are matching as if two operands were swapped, 2998169689Skan also pretend that operands_match had been computed 2999169689Skan with swapped. 3000117395Skan But if I is the second of those and C is the first, 3001169689Skan don't exchange them, because operands_match is valid 3002169689Skan only on one side of its diagonal. */ 3003169689Skan ? (operands_match 3004169689Skan [(c == commutative || c == commutative + 1) 3005169689Skan ? 2 * commutative + 1 - c : c] 3006117395Skan [(i == commutative || i == commutative + 1) 3007169689Skan ? 2 * commutative + 1 - i : i]) 3008169689Skan : operands_match[c][i]) 3009169689Skan { 3010117395Skan /* If we are matching a non-offsettable address where an 3011117395Skan offsettable address was expected, then we must reject 3012169689Skan this combination, because we can't reload it. */ 301318334Speter if (this_alternative_offmemok[c] 3014169689Skan && GET_CODE (recog_data.operand[c]) == MEM 3015169689Skan && this_alternative[c] == (int) NO_REGS 3016169689Skan && ! this_alternative_win[c]) 301790075Sobrien bad = 1; 3018169689Skan 3019169689Skan did_match = this_alternative_win[c]; 302018334Speter } 3021169689Skan else 302218334Speter { 302350397Sobrien /* Operands don't match. */ 302418334Speter rtx value; 302518334Speter /* Retroactively mark the operand we had to match 3026169689Skan as a loser, if it wasn't already. */ 302718334Speter if (this_alternative_win[c]) 3028169689Skan losers++; 3029169689Skan this_alternative_win[c] = 0; 3030169689Skan if (this_alternative[c] == (int) NO_REGS) 3031169689Skan bad = 1; 3032169689Skan /* But count the pair only once in the total badness of 3033169689Skan this alternative, if the pair can be a dummy reload. */ 303418334Speter value 3035169689Skan = find_dummy_reload (recog_data.operand[i], 3036169689Skan recog_data.operand[c], 303718334Speter recog_data.operand_loc[i], 3038169689Skan recog_data.operand_loc[c], 3039169689Skan operand_mode[i], operand_mode[c], 304018334Speter this_alternative[c], -1, 3041169689Skan this_alternative_earlyclobber[c]); 3042169689Skan 3043169689Skan if (value != 0) 304418334Speter losers--; 304518334Speter } 3046169689Skan /* This can be fixed with reloads if the operand 304718334Speter we are supposed to match can be fixed with reloads. */ 3048169689Skan badop = 0; 3049169689Skan this_alternative[i] = this_alternative[c]; 305018334Speter 3051169689Skan /* If we have to reload this operand and some previous 3052169689Skan operand also had to match the same thing as this 3053169689Skan operand, we don't know how to do that. So reject this 3054169689Skan alternative. */ 3055169689Skan if (! did_match || force_reload) 305618334Speter for (j = 0; j < i; j++) 3057169689Skan if (this_alternative_matches[j] 3058169689Skan == this_alternative_matches[i]) 3059169689Skan badop = 1; 3060169689Skan break; 306118334Speter 3062169689Skan case 'p': 306318334Speter /* All necessary reloads for an address_operand 3064169689Skan were handled in find_reloads_address. */ 3065169689Skan this_alternative[i] = (int) MODE_BASE_REG_CLASS (VOIDmode); 3066169689Skan win = 1; 3067169689Skan badop = 0; 3068169689Skan break; 3069169689Skan 3070169689Skan case 'm': 3071169689Skan if (force_reload) 3072169689Skan break; 3073169689Skan if (GET_CODE (operand) == MEM 3074169689Skan || (GET_CODE (operand) == REG 3075169689Skan && REGNO (operand) >= FIRST_PSEUDO_REGISTER 3076169689Skan && reg_renumber[REGNO (operand)] < 0)) 3077169689Skan win = 1; 3078169689Skan if (CONSTANT_P (operand) 3079169689Skan /* force_const_mem does not accept HIGH. */ 3080169689Skan && GET_CODE (operand) != HIGH) 308118334Speter badop = 0; 3082169689Skan constmemok = 1; 308318334Speter break; 3084169689Skan 3085169689Skan case '<': 308618334Speter if (GET_CODE (operand) == MEM 308718334Speter && ! address_reloaded[i] 3088169689Skan && (GET_CODE (XEXP (operand, 0)) == PRE_DEC 308918334Speter || GET_CODE (XEXP (operand, 0)) == POST_DEC)) 309018334Speter win = 1; 309196263Sobrien break; 309296263Sobrien 3093169689Skan case '>': 3094169689Skan if (GET_CODE (operand) == MEM 3095169689Skan && ! address_reloaded[i] 309696263Sobrien && (GET_CODE (XEXP (operand, 0)) == PRE_INC 309796263Sobrien || GET_CODE (XEXP (operand, 0)) == POST_INC)) 309896263Sobrien win = 1; 3099169689Skan break; 3100169689Skan 310118334Speter /* Memory operand whose address is not offsettable. */ 310218334Speter case 'V': 310318334Speter if (force_reload) 3104169689Skan break; 310518334Speter if (GET_CODE (operand) == MEM 310618334Speter && ! (ind_levels ? offsettable_memref_p (operand) 3107169689Skan : offsettable_nonstrict_memref_p (operand)) 3108169689Skan /* Certain mem addresses will become offsettable 3109169689Skan after they themselves are reloaded. This is important; 311018334Speter we don't want our own handling of unoffsettables 311118334Speter to override the handling of reg_equiv_address. */ 311218334Speter && !(GET_CODE (XEXP (operand, 0)) == REG 311396263Sobrien && (ind_levels == 0 311418334Speter || reg_equiv_address[REGNO (XEXP (operand, 0))] != 0))) 311518334Speter win = 1; 3116169689Skan break; 3117169689Skan 3118169689Skan /* Memory operand whose address is offsettable. */ 311918334Speter case 'o': 312018334Speter if (force_reload) 3121169689Skan break; 312218334Speter if ((GET_CODE (operand) == MEM 3123169689Skan /* If IND_LEVELS, find_reloads_address won't reload a 3124169689Skan pseudo that didn't get a hard reg, so we have to 312518334Speter reject that case. */ 3126169689Skan && ((ind_levels ? offsettable_memref_p (operand) 3127169689Skan : offsettable_nonstrict_memref_p (operand)) 3128169689Skan /* A reloaded address is offsettable because it is now 312918334Speter just a simple register indirect. */ 313018334Speter || address_reloaded[i])) 3131169689Skan || (GET_CODE (operand) == REG 3132169689Skan && REGNO (operand) >= FIRST_PSEUDO_REGISTER 313318334Speter && reg_renumber[REGNO (operand)] < 0 3134169689Skan /* If reg_equiv_address is nonzero, we will be 3135169689Skan loading it into a register; hence it will be 313618334Speter offsettable, but we cannot say that reg_equiv_mem 3137169689Skan is offsettable without checking. */ 3138117395Skan && ((reg_equiv_mem[REGNO (operand)] != 0 3139169689Skan && offsettable_memref_p (reg_equiv_mem[REGNO (operand)])) 3140169689Skan || (reg_equiv_address[REGNO (operand)] != 0)))) 3141169689Skan win = 1; 3142169689Skan /* force_const_mem does not accept HIGH. */ 3143169689Skan if ((CONSTANT_P (operand) && GET_CODE (operand) != HIGH) 3144169689Skan || GET_CODE (operand) == MEM) 3145169689Skan badop = 0; 314618334Speter constmemok = 1; 314718334Speter offmemok = 1; 3148169689Skan break; 314918334Speter 3150169689Skan case '&': 3151169689Skan /* Output operand that is stored before the need for the 315218334Speter input operands (and their index registers) is over. */ 3153169689Skan earlyclobber = 1, this_earlyclobber = 1; 315418334Speter break; 3155169689Skan 3156169689Skan case 'E': 315718334Speter#ifndef REAL_ARITHMETIC 3158169689Skan /* Match any floating double constant, but only if 3159169689Skan we can examine the bits of it reliably. */ 316018334Speter if ((HOST_FLOAT_FORMAT != TARGET_FLOAT_FORMAT 3161169689Skan || HOST_BITS_PER_WIDE_INT != BITS_PER_WORD) 3162169689Skan && GET_MODE (operand) != VOIDmode && ! flag_pretend_float) 3163169689Skan break; 316418334Speter#endif 3165169689Skan if (GET_CODE (operand) == CONST_DOUBLE) 3166169689Skan win = 1; 316718334Speter break; 3168169689Skan 3169169689Skan case 'F': 317090075Sobrien if (GET_CODE (operand) == CONST_DOUBLE) 317190075Sobrien win = 1; 317218334Speter break; 317318334Speter 317418334Speter case 'G': 317518334Speter case 'H': 3176132718Skan if (GET_CODE (operand) == CONST_DOUBLE 317718334Speter && CONST_DOUBLE_OK_FOR_LETTER_P (operand, c)) 3178169689Skan win = 1; 3179169689Skan break; 318018334Speter 3181132718Skan case 's': 3182169689Skan if (GET_CODE (operand) == CONST_INT 318390075Sobrien || (GET_CODE (operand) == CONST_DOUBLE 3184169689Skan && GET_MODE (operand) == VOIDmode)) 318518334Speter break; 3186117395Skan case 'i': 3187169689Skan if (CONSTANT_P (operand) 3188117395Skan#ifdef LEGITIMATE_PIC_OPERAND_P 3189117395Skan && (! flag_pic || LEGITIMATE_PIC_OPERAND_P (operand)) 3190169689Skan#endif 3191169689Skan ) 319218334Speter win = 1; 3193169689Skan break; 3194169689Skan 3195169689Skan case 'n': 3196169689Skan if (GET_CODE (operand) == CONST_INT 3197117395Skan || (GET_CODE (operand) == CONST_DOUBLE 3198169689Skan && GET_MODE (operand) == VOIDmode)) 3199169689Skan win = 1; 3200169689Skan break; 3201169689Skan 3202169689Skan case 'I': 3203169689Skan case 'J': 3204169689Skan case 'K': 3205169689Skan case 'L': 3206169689Skan case 'M': 3207169689Skan case 'N': 3208169689Skan case 'O': 3209169689Skan case 'P': 3210169689Skan if (GET_CODE (operand) == CONST_INT 3211169689Skan && CONST_OK_FOR_LETTER_P (INTVAL (operand), c)) 3212169689Skan win = 1; 321390075Sobrien break; 321490075Sobrien 321550397Sobrien case 'X': 3216132718Skan win = 1; 3217169689Skan break; 3218132718Skan 3219132718Skan case 'g': 3220132718Skan if (! force_reload 322150397Sobrien /* A PLUS is never a valid operand, but reload can make 322218334Speter it from a register when eliminating registers. */ 3223169689Skan && GET_CODE (operand) != PLUS 3224169689Skan /* A SCRATCH is not a valid operand. */ 322518334Speter && GET_CODE (operand) != SCRATCH 3226169689Skan#ifdef LEGITIMATE_PIC_OPERAND_P 3227169689Skan && (! CONSTANT_P (operand) 3228169689Skan || ! flag_pic 3229169689Skan || LEGITIMATE_PIC_OPERAND_P (operand)) 3230169689Skan#endif 3231169689Skan && (GENERAL_REGS == ALL_REGS 3232169689Skan || GET_CODE (operand) != REG 3233169689Skan || (REGNO (operand) >= FIRST_PSEUDO_REGISTER 323418334Speter && reg_renumber[REGNO (operand)] < 0))) 3235169689Skan win = 1; 3236169689Skan /* Drop through into 'r' case. */ 3237169689Skan 323890075Sobrien case 'r': 3239169689Skan this_alternative[i] 3240169689Skan = (int) reg_class_subunion[this_alternative[i]][(int) GENERAL_REGS]; 3241117395Skan goto reg; 324290075Sobrien 324390075Sobrien default: 324490075Sobrien if (REG_CLASS_FROM_LETTER (c) == NO_REGS) 324574722Sobrien { 3246169689Skan#ifdef EXTRA_CONSTRAINT 3247169689Skan if (EXTRA_CONSTRAINT (operand, c)) 3248169689Skan win = 1; 3249169689Skan#endif 3250169689Skan break; 3251169689Skan } 3252169689Skan 3253169689Skan this_alternative[i] 3254169689Skan = (int) reg_class_subunion[this_alternative[i]][(int) REG_CLASS_FROM_LETTER (c)]; 3255169689Skan reg: 3256169689Skan if (GET_MODE (operand) == BLKmode) 3257169689Skan break; 3258169689Skan winreg = 1; 3259169689Skan if (GET_CODE (operand) == REG 326018334Speter && reg_fits_class_p (operand, this_alternative[i], 3261169689Skan offset, GET_MODE (recog_data.operand[i]))) 3262169689Skan win = 1; 3263169689Skan break; 3264169689Skan } 3265132718Skan 3266169689Skan constraints[i] = p; 3267169689Skan 3268169689Skan /* If this operand could be handled with a reg, 3269169689Skan and some reg is allowed, then this operand can be handled. */ 327018334Speter if (winreg && this_alternative[i] != (int) NO_REGS) 3271132718Skan badop = 0; 327218334Speter 327318334Speter /* Record which operands fit this alternative. */ 327418334Speter this_alternative_earlyclobber[i] = earlyclobber; 327518334Speter if (win && ! force_reload) 327618334Speter this_alternative_win[i] = 1; 3277132718Skan else if (did_match && ! force_reload) 327818334Speter this_alternative_match_win[i] = 1; 3279169689Skan else 328018334Speter { 328118334Speter int const_to_mem = 0; 328296263Sobrien 328396263Sobrien this_alternative_offmemok[i] = offmemok; 328496263Sobrien losers++; 328596263Sobrien if (badop) 3286132718Skan bad = 1; 328796263Sobrien /* Alternative loses if it has no regs for a reg operand. */ 3288169689Skan if (GET_CODE (operand) == REG 328996263Sobrien && this_alternative[i] == (int) NO_REGS 3290169689Skan && this_alternative_matches[i] < 0) 3291169689Skan bad = 1; 3292169689Skan 329390075Sobrien /* If this is a constant that is reloaded into the desired 329490075Sobrien class by copying it to memory first, count that as another 329518334Speter reload. This is consistent with other code and is 329618334Speter required to avoid choosing another alternative when 329718334Speter the constant is moved into memory by this function on 3298132718Skan an early reload pass. Note that the test here is 329918334Speter precisely the same as in the code below that calls 3300169689Skan force_const_mem. */ 330118334Speter if (CONSTANT_P (operand) 330218334Speter /* force_const_mem does not accept HIGH. */ 330318334Speter && GET_CODE (operand) != HIGH 330418334Speter && ((PREFERRED_RELOAD_CLASS (operand, 330518334Speter (enum reg_class) this_alternative[i]) 3306132718Skan == NO_REGS) 330718334Speter || no_input_reloads) 3308169689Skan && operand_mode[i] != VOIDmode) 330918334Speter { 331018334Speter const_to_mem = 1; 3311169689Skan if (this_alternative[i] != (int) NO_REGS) 3312169689Skan losers++; 331318334Speter } 3314169689Skan 3315169689Skan /* If we can't reload this value at all, reject this 331618334Speter alternative. Note that we could also lose due to 3317169689Skan LIMIT_RELOAD_RELOAD_CLASS, but we don't check that 3318169689Skan here. */ 3319169689Skan 3320169689Skan if (! CONSTANT_P (operand) 3321169689Skan && (enum reg_class) this_alternative[i] != NO_REGS 3322169689Skan && (PREFERRED_RELOAD_CLASS (operand, 332318334Speter (enum reg_class) this_alternative[i]) 3324169689Skan == NO_REGS)) 3325169689Skan bad = 1; 3326169689Skan 3327169689Skan /* Alternative loses if it requires a type of reload not 3328169689Skan permitted for this insn. We can always reload SCRATCH 332950397Sobrien and objects with a REG_UNUSED note. */ 3330169689Skan else if (GET_CODE (operand) != SCRATCH 3331169689Skan && modified[i] != RELOAD_READ && no_output_reloads 3332169689Skan && ! find_reg_note (insn, REG_UNUSED, operand)) 3333169689Skan bad = 1; 333418334Speter else if (modified[i] != RELOAD_WRITE && no_input_reloads 3335169689Skan && ! const_to_mem) 3336169689Skan bad = 1; 3337169689Skan 3338169689Skan /* We prefer to reload pseudos over reloading other things, 3339169689Skan since such reloads may be able to be eliminated later. 3340169689Skan If we are reloading a SCRATCH, we won't be generating any 334190075Sobrien insns, just using a register, so it is also preferred. 3342169689Skan So bump REJECT in other cases. Don't do this in the 3343169689Skan case where we are forcing a constant into memory and 334418334Speter it will then win since we don't want to have a different 3345169689Skan alternative match then. */ 3346169689Skan if (! (GET_CODE (operand) == REG 3347169689Skan && REGNO (operand) >= FIRST_PSEUDO_REGISTER) 3348169689Skan && GET_CODE (operand) != SCRATCH 3349169689Skan && ! (const_to_mem && constmemok)) 3350169689Skan reject += 2; 3351169689Skan 335250397Sobrien /* Input reloads can be inherited more often than output 3353169689Skan reloads can be removed, so penalize output reloads. */ 3354169689Skan if (operand_type[i] != RELOAD_FOR_INPUT 3355169689Skan && GET_CODE (operand) != SCRATCH) 3356169689Skan reject++; 335718334Speter } 3358169689Skan 3359169689Skan /* If this operand is a pseudo register that didn't get a hard 336090075Sobrien reg and this alternative accepts some register, see if the 3361169689Skan class that we want is a subset of the preferred class for this 3362169689Skan register. If not, but it intersects that class, use the 3363169689Skan preferred class instead. If it does not intersect the preferred 3364169689Skan class, show that usage of this alternative should be discouraged; 3365169689Skan it will be discouraged more still if the register is `preferred 336690075Sobrien or nothing'. We do this because it increases the chance of 3367169689Skan reusing our spill register in a later insn and avoiding a pair 336890075Sobrien of memory stores and loads. 3369169689Skan 3370169689Skan Don't bother with this if this alternative will accept this 3371169689Skan operand. 3372169689Skan 3373169689Skan Don't do this for a multiword operand, since it is only a 3374169689Skan small win and has the risk of requiring more spill registers, 3375169689Skan which could cause a large loss. 3376169689Skan 337718334Speter Don't do this if the preferred class has only one register 3378169689Skan because we might otherwise exhaust the class. */ 3379169689Skan 3380169689Skan if (! win && ! did_match 3381169689Skan && this_alternative[i] != (int) NO_REGS 3382169689Skan && GET_MODE_SIZE (operand_mode[i]) <= UNITS_PER_WORD 3383169689Skan && reg_class_size[(int) preferred_class[i]] > 1) 3384169689Skan { 3385169689Skan if (! reg_class_subset_p (this_alternative[i], 3386169689Skan preferred_class[i])) 3387169689Skan { 3388169689Skan /* Since we don't have a way of forming the intersection, 3389169689Skan we just do something special if the preferred class 3390169689Skan is a subset of the class we have; that's the most 3391169689Skan common case anyway. */ 3392169689Skan if (reg_class_subset_p (preferred_class[i], 3393169689Skan this_alternative[i])) 3394169689Skan this_alternative[i] = (int) preferred_class[i]; 3395169689Skan else 3396169689Skan reject += (2 + 2 * pref_or_nothing[i]); 3397169689Skan } 3398169689Skan } 339918334Speter } 3400169689Skan 3401169689Skan /* Now see if any output operands that are marked "earlyclobber" 340218334Speter in this alternative conflict with any input operands 340318334Speter or any memory addresses. */ 3404169689Skan 340518334Speter for (i = 0; i < noperands; i++) 3406169689Skan if (this_alternative_earlyclobber[i] 3407169689Skan && (this_alternative_win[i] || this_alternative_match_win[i])) 340818334Speter { 3409169689Skan struct decomposition early_data; 3410169689Skan 341118334Speter early_data = decompose (recog_data.operand[i]); 3412169689Skan 3413169689Skan if (modified[i] == RELOAD_READ) 3414169689Skan abort (); 3415169689Skan 3416169689Skan if (this_alternative[i] == NO_REGS) 3417169689Skan { 341818334Speter this_alternative_earlyclobber[i] = 0; 3419169689Skan if (this_insn_is_asm) 3420169689Skan error_for_asm (this_insn, 3421169689Skan "`&' constraint used with no register class"); 3422169689Skan else 3423169689Skan abort (); 342418334Speter } 3425169689Skan 3426169689Skan for (j = 0; j < noperands; j++) 3427169689Skan /* Is this an input operand or a memory ref? */ 342896263Sobrien if ((GET_CODE (recog_data.operand[j]) == MEM 3429169689Skan || modified[j] != RELOAD_WRITE) 3430169689Skan && j != i 3431169689Skan /* Ignore things like match_operator operands. */ 3432169689Skan && *recog_data.constraints[j] != 0 343396263Sobrien /* Don't count an input operand that is constrained to match 3434169689Skan the early clobber operand. */ 3435169689Skan && ! (this_alternative_matches[j] == i 343696263Sobrien && rtx_equal_p (recog_data.operand[i], 3437169689Skan recog_data.operand[j])) 3438169689Skan /* Is it altered by storing the earlyclobber operand? */ 3439169689Skan && !immune_p (recog_data.operand[j], recog_data.operand[i], 3440169689Skan early_data)) 3441169689Skan { 3442169689Skan /* If the output is in a single-reg class, 3443169689Skan it's costly to reload it, so reload the input instead. */ 3444169689Skan if (reg_class_size[this_alternative[i]] == 1 3445169689Skan && (GET_CODE (recog_data.operand[j]) == REG 3446169689Skan || GET_CODE (recog_data.operand[j]) == SUBREG)) 3447169689Skan { 3448169689Skan losers++; 3449169689Skan this_alternative_win[j] = 0; 3450169689Skan this_alternative_match_win[j] = 0; 3451169689Skan } 3452169689Skan else 3453169689Skan break; 3454169689Skan } 345596263Sobrien /* If an earlyclobber operand conflicts with something, 3456169689Skan it must be reloaded, so request this and count the cost. */ 3457169689Skan if (j != noperands) 345896263Sobrien { 3459169689Skan losers++; 3460169689Skan this_alternative_win[i] = 0; 3461169689Skan this_alternative_match_win[j] = 0; 3462169689Skan for (j = 0; j < noperands; j++) 346396263Sobrien if (this_alternative_matches[j] == i 3464169689Skan && this_alternative_match_win[j]) 3465169689Skan { 3466169689Skan this_alternative_win[j] = 0; 3467169689Skan this_alternative_match_win[j] = 0; 3468169689Skan losers++; 346996263Sobrien } 3470169689Skan } 3471169689Skan } 3472169689Skan 3473169689Skan /* If one alternative accepts all the operands, no reload required, 3474169689Skan choose that alternative; don't consider the remaining ones. */ 3475169689Skan if (losers == 0) 3476169689Skan { 3477169689Skan /* Unswap these so that they are never swapped at `finish'. */ 3478169689Skan if (commutative >= 0) 3479169689Skan { 3480169689Skan recog_data.operand[commutative] = substed_operand[commutative]; 3481169689Skan recog_data.operand[commutative + 1] 348218334Speter = substed_operand[commutative + 1]; 348318334Speter } 3484169689Skan for (i = 0; i < noperands; i++) 3485169689Skan { 348618334Speter goal_alternative_win[i] = this_alternative_win[i]; 348750397Sobrien goal_alternative_match_win[i] = this_alternative_match_win[i]; 348850397Sobrien goal_alternative[i] = this_alternative[i]; 3489169689Skan goal_alternative_offmemok[i] = this_alternative_offmemok[i]; 3490169689Skan goal_alternative_matches[i] = this_alternative_matches[i]; 349150397Sobrien goal_alternative_earlyclobber[i] 349250397Sobrien = this_alternative_earlyclobber[i]; 3493132718Skan } 349450397Sobrien goal_alternative_number = this_alternative_number; 3495169689Skan goal_alternative_swapped = swapped; 349650397Sobrien goal_earlyclobber = this_earlyclobber; 3497169689Skan goto finish; 349850397Sobrien } 349950397Sobrien 350050397Sobrien /* REJECT, set by the ! and ? constraint characters and when a register 3501169689Skan would be reloaded into a non-preferred class, discourages the use of 350250397Sobrien this alternative for a reload goal. REJECT is incremented by six 3503117395Skan for each ? and two for each non-preferred class. */ 3504117395Skan losers = losers * 6 + reject; 3505117395Skan 3506169689Skan /* If this alternative can be made to work by reloading, 350790075Sobrien and it needs less reloading than the others checked so far, 350852284Sobrien record it as the chosen goal for reloading. */ 3509169689Skan if (! bad && best > losers) 351052284Sobrien { 351150397Sobrien for (i = 0; i < noperands; i++) 3512169689Skan { 351350397Sobrien goal_alternative[i] = this_alternative[i]; 3514169689Skan goal_alternative_win[i] = this_alternative_win[i]; 351550397Sobrien goal_alternative_match_win[i] = this_alternative_match_win[i]; 3516169689Skan goal_alternative_offmemok[i] = this_alternative_offmemok[i]; 3517169689Skan goal_alternative_matches[i] = this_alternative_matches[i]; 3518169689Skan goal_alternative_earlyclobber[i] 3519169689Skan = this_alternative_earlyclobber[i]; 3520169689Skan } 3521169689Skan goal_alternative_swapped = swapped; 3522169689Skan best = losers; 3523169689Skan goal_alternative_number = this_alternative_number; 3524169689Skan goal_earlyclobber = this_earlyclobber; 3525169689Skan } 3526169689Skan } 3527169689Skan 3528169689Skan /* If insn is commutative (it's safe to exchange a certain pair of operands) 3529169689Skan then we need to try each alternative twice, 3530169689Skan the second time matching those two operands 3531169689Skan as if we had exchanged them. 3532169689Skan To do this, really exchange them in operands. 3533169689Skan 353450397Sobrien If we have just tried the alternatives the second time, 3535169689Skan return operands to normal and drop through. */ 3536169689Skan 353750397Sobrien if (commutative >= 0) 3538169689Skan { 3539169689Skan swapped = !swapped; 3540169689Skan if (swapped) 3541169689Skan { 3542169689Skan enum reg_class tclass; 354350397Sobrien int t; 3544169689Skan 3545169689Skan recog_data.operand[commutative] = substed_operand[commutative + 1]; 3546169689Skan recog_data.operand[commutative + 1] = substed_operand[commutative]; 3547169689Skan /* Swap the duplicates too. */ 354850397Sobrien for (i = 0; i < recog_data.n_dups; i++) 3549169689Skan if (recog_data.dup_num[i] == commutative 3550169689Skan || recog_data.dup_num[i] == commutative + 1) 3551169689Skan *recog_data.dup_loc[i] 355250397Sobrien = recog_data.operand[(int) recog_data.dup_num[i]]; 3553169689Skan 355450397Sobrien tclass = preferred_class[commutative]; 3555169689Skan preferred_class[commutative] = preferred_class[commutative + 1]; 3556169689Skan preferred_class[commutative + 1] = tclass; 3557169689Skan 355850397Sobrien t = pref_or_nothing[commutative]; 3559169689Skan pref_or_nothing[commutative] = pref_or_nothing[commutative + 1]; 3560169689Skan pref_or_nothing[commutative + 1] = t; 356190075Sobrien 3562169689Skan memcpy (constraints, recog_data.constraints, 3563169689Skan noperands * sizeof (char *)); 356490075Sobrien goto try_swapped; 3565169689Skan } 356690075Sobrien else 356718334Speter { 3568132718Skan recog_data.operand[commutative] = substed_operand[commutative]; 356918334Speter recog_data.operand[commutative + 1] 3570132718Skan = substed_operand[commutative + 1]; 3571132718Skan /* Unswap the duplicates too. */ 357218334Speter for (i = 0; i < recog_data.n_dups; i++) 3573117395Skan if (recog_data.dup_num[i] == commutative 357490075Sobrien || recog_data.dup_num[i] == commutative + 1) 357518334Speter *recog_data.dup_loc[i] 357690075Sobrien = recog_data.operand[(int) recog_data.dup_num[i]]; 357790075Sobrien } 3578169689Skan } 357990075Sobrien 358018334Speter /* The operands don't meet the constraints. 358118334Speter goal_alternative describes the alternative 358218334Speter that we could reach by reloading the fewest operands. 3583102780Skan Reload so as to fit it. */ 358490075Sobrien 358590075Sobrien if (best == MAX_RECOG_OPERANDS * 2 + 600) 358690075Sobrien { 358790075Sobrien /* No alternative works with reloads?? */ 358890075Sobrien if (insn_code_number >= 0) 358990075Sobrien fatal_insn ("unable to generate reloads for:", insn); 359018334Speter error_for_asm (insn, "inconsistent operand constraints in an `asm'"); 359190075Sobrien /* Avoid further trouble with this insn. */ 359290075Sobrien PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx); 359390075Sobrien n_reloads = 0; 359490075Sobrien return 0; 359518334Speter } 359618334Speter 359718334Speter /* Jump to `finish' from above if all operands are valid already. 3598132718Skan In that case, goal_alternative_win is all 1. */ 3599132718Skan finish: 360018334Speter 360118334Speter /* Right now, for any pair of operands I and J that are required to match, 3602117395Skan with I < J, 3603132718Skan goal_alternative_matches[J] is I. 3604132718Skan Set up goal_alternative_matched as the inverse function: 3605117395Skan goal_alternative_matched[I] = J. */ 3606117395Skan 3607117395Skan for (i = 0; i < noperands; i++) 3608117395Skan goal_alternative_matched[i] = -1; 3609117395Skan 3610117395Skan for (i = 0; i < noperands; i++) 3611117395Skan if (! goal_alternative_win[i] 361218334Speter && goal_alternative_matches[i] >= 0) 361318334Speter goal_alternative_matched[goal_alternative_matches[i]] = i; 361418334Speter 3615169689Skan for (i = 0; i < noperands; i++) 3616132718Skan goal_alternative_win[i] |= goal_alternative_match_win[i]; 361718334Speter 361818334Speter /* If the best alternative is with operands 1 and 2 swapped, 361918334Speter consider them swapped before reporting the reloads. Update the 3620169689Skan operand numbers of any reloads already pushed. */ 3621169689Skan 3622169689Skan if (goal_alternative_swapped) 3623169689Skan { 3624169689Skan rtx tem; 3625169689Skan 362618334Speter tem = substed_operand[commutative]; 362718334Speter substed_operand[commutative] = substed_operand[commutative + 1]; 362850397Sobrien substed_operand[commutative + 1] = tem; 362918334Speter tem = recog_data.operand[commutative]; 363018334Speter recog_data.operand[commutative] = recog_data.operand[commutative + 1]; 363118334Speter recog_data.operand[commutative + 1] = tem; 363218334Speter tem = *recog_data.operand_loc[commutative]; 3633132718Skan *recog_data.operand_loc[commutative] 3634132718Skan = *recog_data.operand_loc[commutative + 1]; 3635132718Skan *recog_data.operand_loc[commutative + 1] = tem; 3636132718Skan 3637132718Skan for (i = 0; i < n_reloads; i++) 3638132718Skan { 3639132718Skan if (rld[i].opnum == commutative) 3640132718Skan rld[i].opnum = commutative + 1; 3641132718Skan else if (rld[i].opnum == commutative + 1) 3642132718Skan rld[i].opnum = commutative; 3643132718Skan } 3644132718Skan } 3645169689Skan 3646132718Skan for (i = 0; i < noperands; i++) 3647132718Skan { 3648132718Skan operand_reloadnum[i] = -1; 3649132718Skan 3650132718Skan /* If this is an earlyclobber operand, we need to widen the scope. 3651132718Skan The reload must remain valid from the start of the insn being 3652132718Skan reloaded until after the operand is stored into its destination. 3653132718Skan We approximate this with RELOAD_OTHER even though we know that we 3654132718Skan do not conflict with RELOAD_FOR_INPUT_ADDRESS reloads. 3655132718Skan 3656132718Skan One special case that is worth checking is when we have an 3657132718Skan output that is earlyclobber but isn't used past the insn (typically 3658169689Skan a SCRATCH). In this case, we only need have the reload live 3659169689Skan through the insn itself, but not for any of our input or output 3660169689Skan reloads. 3661169689Skan But we must not accidentally narrow the scope of an existing 3662169689Skan RELOAD_OTHER reload - leave these alone. 3663132718Skan 3664132718Skan In any case, anything needed to address this operand can remain 3665132718Skan however they were previously categorized. */ 3666132718Skan 3667132718Skan if (goal_alternative_earlyclobber[i] && operand_type[i] != RELOAD_OTHER) 3668132718Skan operand_type[i] 3669132718Skan = (find_reg_note (insn, REG_UNUSED, recog_data.operand[i]) 3670132718Skan ? RELOAD_FOR_INSN : RELOAD_OTHER); 3671132718Skan } 3672132718Skan 3673132718Skan /* Any constants that aren't allowed and can't be reloaded 3674169689Skan into registers are here changed into memory references. */ 3675132718Skan for (i = 0; i < noperands; i++) 3676132718Skan if (! goal_alternative_win[i] 3677132718Skan && CONSTANT_P (recog_data.operand[i]) 3678132718Skan /* force_const_mem does not accept HIGH. */ 3679169689Skan && GET_CODE (recog_data.operand[i]) != HIGH 3680169689Skan && ((PREFERRED_RELOAD_CLASS (recog_data.operand[i], 3681169689Skan (enum reg_class) goal_alternative[i]) 3682169689Skan == NO_REGS) 3683169689Skan || no_input_reloads) 3684169689Skan && operand_mode[i] != VOIDmode) 3685132718Skan { 3686132718Skan substed_operand[i] = recog_data.operand[i] 3687132718Skan = find_reloads_toplev (force_const_mem (operand_mode[i], 3688132718Skan recog_data.operand[i]), 3689132718Skan i, address_type[i], ind_levels, 0, insn, 3690132718Skan NULL); 369118334Speter if (alternative_allows_memconst (recog_data.constraints[i], 3692169689Skan goal_alternative_number)) 3693169689Skan goal_alternative_win[i] = 1; 3694169689Skan } 3695169689Skan 3696169689Skan /* Record the values of the earlyclobber operands for the caller. */ 3697169689Skan if (goal_earlyclobber) 3698169689Skan for (i = 0; i < noperands; i++) 3699169689Skan if (goal_alternative_earlyclobber[i]) 3700169689Skan reload_earlyclobbers[n_earlyclobbers++] = recog_data.operand[i]; 3701169689Skan 3702169689Skan /* Now record reloads for all the operands that need them. */ 3703169689Skan for (i = 0; i < noperands; i++) 3704169689Skan if (! goal_alternative_win[i]) 3705169689Skan { 370690075Sobrien /* Operands that match previous ones have already been handled. */ 370790075Sobrien if (goal_alternative_matches[i] >= 0) 370890075Sobrien ; 370990075Sobrien /* Handle an operand with a nonoffsettable address 371090075Sobrien appearing where an offsettable address will do 371190075Sobrien by reloading the address into a base register. 371290075Sobrien 371390075Sobrien ??? We can also do this when the operand is a register and 371490075Sobrien reg_equiv_mem is not offsettable, but this is a bit tricky, 371590075Sobrien so we don't bother with it. It may not be worth doing. */ 371690075Sobrien else if (goal_alternative_matched[i] == -1 3717132718Skan && goal_alternative_offmemok[i] 371890075Sobrien && GET_CODE (recog_data.operand[i]) == MEM) 371990075Sobrien { 372090075Sobrien operand_reloadnum[i] 3721169689Skan = push_reload (XEXP (recog_data.operand[i], 0), NULL_RTX, 372290075Sobrien &XEXP (recog_data.operand[i], 0), (rtx*) 0, 372390075Sobrien MODE_BASE_REG_CLASS (VOIDmode), 372490075Sobrien GET_MODE (XEXP (recog_data.operand[i], 0)), 372590075Sobrien VOIDmode, 0, 0, i, RELOAD_FOR_INPUT); 3726169689Skan rld[operand_reloadnum[i]].inc 3727122180Skan = GET_MODE_SIZE (GET_MODE (recog_data.operand[i])); 3728169689Skan 3729122180Skan /* If this operand is an output, we will have made any 3730122180Skan reloads for its address as RELOAD_FOR_OUTPUT_ADDRESS, but 373190075Sobrien now we are treating part of the operand as an input, so 3732169689Skan we must change these to RELOAD_FOR_INPUT_ADDRESS. */ 3733122180Skan 3734122180Skan if (modified[i] == RELOAD_WRITE) 3735169689Skan { 3736122180Skan for (j = 0; j < n_reloads; j++) 3737122180Skan { 3738122180Skan if (rld[j].opnum == i) 3739122180Skan { 3740122180Skan if (rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS) 3741122180Skan rld[j].when_needed = RELOAD_FOR_INPUT_ADDRESS; 3742122180Skan else if (rld[j].when_needed 3743122180Skan == RELOAD_FOR_OUTADDR_ADDRESS) 3744122180Skan rld[j].when_needed = RELOAD_FOR_INPADDR_ADDRESS; 3745122180Skan } 374690075Sobrien } 3747122180Skan } 3748122180Skan } 374990075Sobrien else if (goal_alternative_matched[i] == -1) 375096263Sobrien { 375190075Sobrien operand_reloadnum[i] 375290075Sobrien = push_reload ((modified[i] != RELOAD_WRITE 375390075Sobrien ? recog_data.operand[i] : 0), 375490075Sobrien (modified[i] != RELOAD_READ 375590075Sobrien ? recog_data.operand[i] : 0), 375690075Sobrien (modified[i] != RELOAD_WRITE 375790075Sobrien ? recog_data.operand_loc[i] : 0), 3758169689Skan (modified[i] != RELOAD_READ 3759169689Skan ? recog_data.operand_loc[i] : 0), 3760169689Skan (enum reg_class) goal_alternative[i], 3761169689Skan (modified[i] == RELOAD_WRITE 3762169689Skan ? VOIDmode : operand_mode[i]), 3763169689Skan (modified[i] == RELOAD_READ 3764169689Skan ? VOIDmode : operand_mode[i]), 3765169689Skan (insn_code_number < 0 ? 0 3766169689Skan : insn_data[insn_code_number].operand[i].strict_low), 3767169689Skan 0, i, operand_type[i]); 3768169689Skan } 3769169689Skan /* In a matching pair of operands, one must be input only 3770169689Skan and the other must be output only. 3771169689Skan Pass the input operand as IN and the other as OUT. */ 3772169689Skan else if (modified[i] == RELOAD_READ 3773169689Skan && modified[goal_alternative_matched[i]] == RELOAD_WRITE) 3774169689Skan { 3775169689Skan operand_reloadnum[i] 3776169689Skan = push_reload (recog_data.operand[i], 3777169689Skan recog_data.operand[goal_alternative_matched[i]], 377890075Sobrien recog_data.operand_loc[i], 377990075Sobrien recog_data.operand_loc[goal_alternative_matched[i]], 378090075Sobrien (enum reg_class) goal_alternative[i], 378190075Sobrien operand_mode[i], 378290075Sobrien operand_mode[goal_alternative_matched[i]], 378390075Sobrien 0, 0, i, RELOAD_OTHER); 378490075Sobrien operand_reloadnum[goal_alternative_matched[i]] = output_reloadnum; 3785146895Skan } 3786146895Skan else if (modified[i] == RELOAD_WRITE 3787146895Skan && modified[goal_alternative_matched[i]] == RELOAD_READ) 3788146895Skan { 378990075Sobrien operand_reloadnum[goal_alternative_matched[i]] 3790146895Skan = push_reload (recog_data.operand[goal_alternative_matched[i]], 3791146895Skan recog_data.operand[i], 3792146895Skan recog_data.operand_loc[goal_alternative_matched[i]], 379390075Sobrien recog_data.operand_loc[i], 3794146895Skan (enum reg_class) goal_alternative[i], 3795146895Skan operand_mode[goal_alternative_matched[i]], 3796146895Skan operand_mode[i], 3797146895Skan 0, 0, i, RELOAD_OTHER); 3798146895Skan operand_reloadnum[i] = output_reloadnum; 3799146895Skan } 3800146895Skan else if (insn_code_number >= 0) 380190075Sobrien abort (); 3802146895Skan else 3803146895Skan { 3804146895Skan error_for_asm (insn, "inconsistent operand constraints in an `asm'"); 3805146895Skan /* Avoid further trouble with this insn. */ 380690075Sobrien PATTERN (insn) = gen_rtx_USE (VOIDmode, const0_rtx); 3807146895Skan n_reloads = 0; 3808146895Skan return 0; 3809146895Skan } 3810146895Skan } 3811146895Skan else if (goal_alternative_matched[i] < 0 3812146895Skan && goal_alternative_matches[i] < 0 3813146895Skan && optimize) 3814146895Skan { 3815146895Skan /* For each non-matching operand that's a MEM or a pseudo-register 381690075Sobrien that didn't get a hard register, make an optional reload. 3817146895Skan This may get done even if the insn needs no reloads otherwise. */ 3818146895Skan 3819146895Skan rtx operand = recog_data.operand[i]; 3820146895Skan 382190075Sobrien while (GET_CODE (operand) == SUBREG) 3822146895Skan operand = SUBREG_REG (operand); 3823146895Skan if ((GET_CODE (operand) == MEM 3824146895Skan || (GET_CODE (operand) == REG 3825146895Skan && REGNO (operand) >= FIRST_PSEUDO_REGISTER)) 3826146895Skan /* If this is only for an output, the optional reload would not 3827146895Skan actually cause us to use a register now, just note that 3828169689Skan something is stored here. */ 3829169689Skan && ((enum reg_class) goal_alternative[i] != NO_REGS 3830169689Skan || modified[i] == RELOAD_WRITE) 3831146895Skan && ! no_input_reloads 3832146895Skan /* An optional output reload might allow to delete INSN later. 3833146895Skan We mustn't make in-out reloads on insns that are not permitted 3834146895Skan output reloads. 3835146895Skan If this is an asm, we can't delete it; we must not even call 3836146895Skan push_reload for an optional output reload in this case, 3837146895Skan because we can't be sure that the constraint allows a register, 3838146895Skan and push_reload verifies the constraints for asms. */ 3839146895Skan && (modified[i] == RELOAD_READ 3840146895Skan || (! no_output_reloads && ! this_insn_is_asm))) 3841146895Skan operand_reloadnum[i] 3842146895Skan = push_reload ((modified[i] != RELOAD_WRITE 384390075Sobrien ? recog_data.operand[i] : 0), 384490075Sobrien (modified[i] != RELOAD_READ 384590075Sobrien ? recog_data.operand[i] : 0), 384690075Sobrien (modified[i] != RELOAD_WRITE 384790075Sobrien ? recog_data.operand_loc[i] : 0), 3848117395Skan (modified[i] != RELOAD_READ 384990075Sobrien ? recog_data.operand_loc[i] : 0), 385090075Sobrien (enum reg_class) goal_alternative[i], 385190075Sobrien (modified[i] == RELOAD_WRITE 385290075Sobrien ? VOIDmode : operand_mode[i]), 385390075Sobrien (modified[i] == RELOAD_READ 385490075Sobrien ? VOIDmode : operand_mode[i]), 385590075Sobrien (insn_code_number < 0 ? 0 385690075Sobrien : insn_data[insn_code_number].operand[i].strict_low), 385790075Sobrien 1, i, operand_type[i]); 3858117395Skan /* If a memory reference remains (either as a MEM or a pseudo that 385990075Sobrien did not get a hard register), yet we can't make an optional 386090075Sobrien reload, check if this is actually a pseudo register reference; 386190075Sobrien we then need to emit a USE and/or a CLOBBER so that reload 386290075Sobrien inheritance will do the right thing. */ 386390075Sobrien else if (replace 386490075Sobrien && (GET_CODE (operand) == MEM 386590075Sobrien || (GET_CODE (operand) == REG 386690075Sobrien && REGNO (operand) >= FIRST_PSEUDO_REGISTER 386790075Sobrien && reg_renumber [REGNO (operand)] < 0))) 386890075Sobrien { 386990075Sobrien operand = *recog_data.operand_loc[i]; 387090075Sobrien 387190075Sobrien while (GET_CODE (operand) == SUBREG) 387290075Sobrien operand = SUBREG_REG (operand); 387390075Sobrien if (GET_CODE (operand) == REG) 387490075Sobrien { 387590075Sobrien if (modified[i] != RELOAD_WRITE) 387690075Sobrien /* We mark the USE with QImode so that we recognize 387790075Sobrien it as one that can be safely deleted at the end 387890075Sobrien of reload. */ 387990075Sobrien PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, operand), 3880169689Skan insn), QImode); 3881169689Skan if (modified[i] != RELOAD_READ) 3882169689Skan emit_insn_after (gen_rtx_CLOBBER (VOIDmode, operand), insn); 388390075Sobrien } 388490075Sobrien } 388590075Sobrien } 3886169689Skan else if (goal_alternative_matches[i] >= 0 388790075Sobrien && goal_alternative_win[goal_alternative_matches[i]] 388890075Sobrien && modified[i] == RELOAD_READ 388990075Sobrien && modified[goal_alternative_matches[i]] == RELOAD_WRITE 3890169689Skan && ! no_input_reloads && ! no_output_reloads 389190075Sobrien && optimize) 389290075Sobrien { 389390075Sobrien /* Similarly, make an optional reload for a pair of matching 389496263Sobrien objects that are in MEM or a pseudo that didn't get a hard reg. */ 3895132718Skan 389696263Sobrien rtx operand = recog_data.operand[i]; 389796263Sobrien 389896263Sobrien while (GET_CODE (operand) == SUBREG) 389996263Sobrien operand = SUBREG_REG (operand); 390096263Sobrien if ((GET_CODE (operand) == MEM 390196263Sobrien || (GET_CODE (operand) == REG 390296263Sobrien && REGNO (operand) >= FIRST_PSEUDO_REGISTER)) 390396263Sobrien && ((enum reg_class) goal_alternative[goal_alternative_matches[i]] 390496263Sobrien != NO_REGS)) 390596263Sobrien operand_reloadnum[i] = operand_reloadnum[goal_alternative_matches[i]] 390696263Sobrien = push_reload (recog_data.operand[goal_alternative_matches[i]], 390796263Sobrien recog_data.operand[i], 390896263Sobrien recog_data.operand_loc[goal_alternative_matches[i]], 390996263Sobrien recog_data.operand_loc[i], 391096263Sobrien (enum reg_class) goal_alternative[goal_alternative_matches[i]], 391196263Sobrien operand_mode[goal_alternative_matches[i]], 391296263Sobrien operand_mode[i], 391396263Sobrien 0, 1, goal_alternative_matches[i], RELOAD_OTHER); 391496263Sobrien } 391596263Sobrien 391696263Sobrien /* Perform whatever substitutions on the operands we are supposed 391796263Sobrien to make due to commutativity or replacement of registers 391896263Sobrien with equivalent constants or memory slots. */ 391996263Sobrien 392096263Sobrien for (i = 0; i < noperands; i++) 392196263Sobrien { 392296263Sobrien /* We only do this on the last pass through reload, because it is 392396263Sobrien possible for some data (like reg_equiv_address) to be changed during 392496263Sobrien later passes. Moreover, we loose the opportunity to get a useful 3925169689Skan reload_{in,out}_reg when we do these replacements. */ 3926169689Skan 3927169689Skan if (replace) 3928169689Skan { 3929169689Skan rtx substitution = substed_operand[i]; 3930169689Skan 3931169689Skan *recog_data.operand_loc[i] = substitution; 3932169689Skan 3933169689Skan /* If we're replacing an operand with a LABEL_REF, we need 3934169689Skan to make sure that there's a REG_LABEL note attached to 3935169689Skan this instruction. */ 3936169689Skan if (GET_CODE (insn) != JUMP_INSN 3937169689Skan && GET_CODE (substitution) == LABEL_REF 3938169689Skan && !find_reg_note (insn, REG_LABEL, XEXP (substitution, 0))) 3939169689Skan REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL, 3940169689Skan XEXP (substitution, 0), 3941169689Skan REG_NOTES (insn)); 3942169689Skan } 3943169689Skan else 394490075Sobrien retval |= (substed_operand[i] != *recog_data.operand_loc[i]); 394590075Sobrien } 394690075Sobrien 394790075Sobrien /* If this insn pattern contains any MATCH_DUP's, make sure that 394890075Sobrien they will be substituted if the operands they match are substituted. 394990075Sobrien Also do now any substitutions we already did on the operands. 395090075Sobrien 395190075Sobrien Don't do this if we aren't making replacements because we might be 395290075Sobrien propagating things allocated by frame pointer elimination into places 395390075Sobrien it doesn't expect. */ 395418334Speter 395518334Speter if (insn_code_number >= 0 && replace) 395618334Speter for (i = insn_data[insn_code_number].n_dups - 1; i >= 0; i--) 395718334Speter { 395818334Speter int opno = recog_data.dup_num[i]; 395918334Speter *recog_data.dup_loc[i] = *recog_data.operand_loc[opno]; 396018334Speter if (operand_reloadnum[opno] >= 0) 396118334Speter push_replacement (recog_data.dup_loc[i], operand_reloadnum[opno], 396218334Speter insn_data[insn_code_number].operand[opno].mode); 396318334Speter } 396418334Speter 396518334Speter#if 0 396618334Speter /* This loses because reloading of prior insns can invalidate the equivalence 396718334Speter (or at least find_equiv_reg isn't smart enough to find it any more), 396818334Speter causing this insn to need more reload regs than it needed before. 396918334Speter It may be too late to make the reload regs available. 397090075Sobrien Now this optimization is done safely in choose_reload_regs. */ 397118334Speter 397290075Sobrien /* For each reload of a reg into some other class of reg, 397390075Sobrien search for an existing equivalent reg (same value now) in the right class. 397418334Speter We can use it as long as we don't need to change its contents. */ 3975132718Skan for (i = 0; i < n_reloads; i++) 397618334Speter if (rld[i].reg_rtx == 0 397790075Sobrien && rld[i].in != 0 3978132718Skan && GET_CODE (rld[i].in) == REG 397918334Speter && rld[i].out == 0) 3980132718Skan { 398190075Sobrien rld[i].reg_rtx 398290075Sobrien = find_equiv_reg (rld[i].in, insn, rld[i].class, -1, 3983169689Skan static_reload_reg_p, 0, rld[i].inmode); 398452284Sobrien /* Prevent generation of insn to load the value 398552284Sobrien because the one we found already has the value. */ 398618334Speter if (rld[i].reg_rtx) 398718334Speter rld[i].in = rld[i].reg_rtx; 3988169689Skan } 3989169689Skan#endif 3990169689Skan 3991169689Skan /* Perhaps an output reload can be combined with another 3992169689Skan to reduce needs by one. */ 3993169689Skan if (!goal_earlyclobber) 3994169689Skan combine_reloads (); 3995169689Skan 3996169689Skan /* If we have a pair of reloads for parts of an address, they are reloading 3997169689Skan the same object, the operands themselves were not reloaded, and they 3998169689Skan are for two operands that are supposed to match, merge the reloads and 3999169689Skan change the type of the surviving reload to RELOAD_FOR_OPERAND_ADDRESS. */ 4000169689Skan 4001169689Skan for (i = 0; i < n_reloads; i++) 4002169689Skan { 4003169689Skan int k; 4004169689Skan 4005169689Skan for (j = i + 1; j < n_reloads; j++) 4006169689Skan if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS 4007169689Skan || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS 4008169689Skan || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS 4009169689Skan || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS) 4010169689Skan && (rld[j].when_needed == RELOAD_FOR_INPUT_ADDRESS 4011169689Skan || rld[j].when_needed == RELOAD_FOR_OUTPUT_ADDRESS 4012169689Skan || rld[j].when_needed == RELOAD_FOR_INPADDR_ADDRESS 4013169689Skan || rld[j].when_needed == RELOAD_FOR_OUTADDR_ADDRESS) 4014169689Skan && rtx_equal_p (rld[i].in, rld[j].in) 4015169689Skan && (operand_reloadnum[rld[i].opnum] < 0 4016169689Skan || rld[operand_reloadnum[rld[i].opnum]].optional) 401790075Sobrien && (operand_reloadnum[rld[j].opnum] < 0 401890075Sobrien || rld[operand_reloadnum[rld[j].opnum]].optional) 401990075Sobrien && (goal_alternative_matches[rld[i].opnum] == rld[j].opnum 402090075Sobrien || (goal_alternative_matches[rld[j].opnum] 402190075Sobrien == rld[i].opnum))) 4022169689Skan { 4023169689Skan for (k = 0; k < n_replacements; k++) 4024169689Skan if (replacements[k].what == j) 402518334Speter replacements[k].what = i; 4026169689Skan 4027169689Skan if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS 4028169689Skan || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS) 4029169689Skan rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR; 4030169689Skan else 4031169689Skan rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS; 4032169689Skan rld[j].in = 0; 4033169689Skan } 4034169689Skan } 4035169689Skan 4036169689Skan /* Scan all the reloads and update their type. 4037169689Skan If a reload is for the address of an operand and we didn't reload 403890075Sobrien that operand, change the type. Similarly, change the operand number 403990075Sobrien of a reload when two operands match. If a reload is optional, treat it 404090075Sobrien as though the operand isn't reloaded. 4041169689Skan 4042169689Skan ??? This latter case is somewhat odd because if we do the optional 4043169689Skan reload, it means the object is hanging around. Thus we need only 404418334Speter do the address reload if the optional reload was NOT done. 404518334Speter 4046169689Skan Change secondary reloads to be the address type of their operand, not 4047169689Skan the normal type. 404818334Speter 404950397Sobrien If an operand's reload is now RELOAD_OTHER, change any 405018334Speter RELOAD_FOR_INPUT_ADDRESS reloads of that operand to 405118334Speter RELOAD_FOR_OTHER_ADDRESS. */ 405218334Speter 405390075Sobrien for (i = 0; i < n_reloads; i++) 405490075Sobrien { 405590075Sobrien if (rld[i].secondary_p 405690075Sobrien && rld[i].when_needed == operand_type[rld[i].opnum]) 405790075Sobrien rld[i].when_needed = address_type[rld[i].opnum]; 405890075Sobrien 405990075Sobrien if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS 4060169689Skan || rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS 406190075Sobrien || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS 406290075Sobrien || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS) 406390075Sobrien && (operand_reloadnum[rld[i].opnum] < 0 406490075Sobrien || rld[operand_reloadnum[rld[i].opnum]].optional)) 406590075Sobrien { 4066169689Skan /* If we have a secondary reload to go along with this reload, 406718334Speter change its type to RELOAD_FOR_OPADDR_ADDR. */ 406818334Speter 406918334Speter if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS 407018334Speter || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS) 407118334Speter && rld[i].secondary_in_reload != -1) 407218334Speter { 407318334Speter int secondary_in_reload = rld[i].secondary_in_reload; 4074261188Spfg 4075261188Spfg rld[secondary_in_reload].when_needed = RELOAD_FOR_OPADDR_ADDR; 4076132718Skan 407718334Speter /* If there's a tertiary reload we have to change it also. */ 407818334Speter if (secondary_in_reload > 0 4079169689Skan && rld[secondary_in_reload].secondary_in_reload != -1) 408018334Speter rld[rld[secondary_in_reload].secondary_in_reload].when_needed 408118334Speter = RELOAD_FOR_OPADDR_ADDR; 408218334Speter } 408318334Speter 408418334Speter if ((rld[i].when_needed == RELOAD_FOR_OUTPUT_ADDRESS 408518334Speter || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS) 408618334Speter && rld[i].secondary_out_reload != -1) 4087132718Skan { 408818334Speter int secondary_out_reload = rld[i].secondary_out_reload; 408918334Speter 409018334Speter rld[secondary_out_reload].when_needed = RELOAD_FOR_OPADDR_ADDR; 409190075Sobrien 409290075Sobrien /* If there's a tertiary reload we have to change it also. */ 409390075Sobrien if (secondary_out_reload 409418334Speter && rld[secondary_out_reload].secondary_out_reload != -1) 409518334Speter rld[rld[secondary_out_reload].secondary_out_reload].when_needed 409618334Speter = RELOAD_FOR_OPADDR_ADDR; 409796263Sobrien } 4098169689Skan 409918334Speter if (rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS 4100169689Skan || rld[i].when_needed == RELOAD_FOR_OUTADDR_ADDRESS) 410190075Sobrien rld[i].when_needed = RELOAD_FOR_OPADDR_ADDR; 410218334Speter else 4103169689Skan rld[i].when_needed = RELOAD_FOR_OPERAND_ADDRESS; 4104132718Skan } 4105132718Skan 410690075Sobrien if ((rld[i].when_needed == RELOAD_FOR_INPUT_ADDRESS 4107169689Skan || rld[i].when_needed == RELOAD_FOR_INPADDR_ADDRESS) 4108119256Skan && operand_reloadnum[rld[i].opnum] >= 0 4109169689Skan && (rld[operand_reloadnum[rld[i].opnum]].when_needed 4110169689Skan == RELOAD_OTHER)) 4111169689Skan rld[i].when_needed = RELOAD_FOR_OTHER_ADDRESS; 4112169689Skan 4113169689Skan if (goal_alternative_matches[rld[i].opnum] >= 0) 4114169689Skan rld[i].opnum = goal_alternative_matches[rld[i].opnum]; 4115119256Skan } 4116169689Skan 4117169689Skan /* Scan all the reloads, and check for RELOAD_FOR_OPERAND_ADDRESS reloads. 4118119256Skan If we have more than one, then convert all RELOAD_FOR_OPADDR_ADDR 4119169689Skan reloads to RELOAD_FOR_OPERAND_ADDRESS reloads. 4120169689Skan 4121169689Skan choose_reload_regs assumes that RELOAD_FOR_OPADDR_ADDR reloads never 4122169689Skan conflict with RELOAD_FOR_OPERAND_ADDRESS reloads. This is true for a 4123169689Skan single pair of RELOAD_FOR_OPADDR_ADDR/RELOAD_FOR_OPERAND_ADDRESS reloads. 4124169689Skan However, if there is more than one RELOAD_FOR_OPERAND_ADDRESS reload, 4125169689Skan then a RELOAD_FOR_OPADDR_ADDR reload conflicts with all 4126169689Skan RELOAD_FOR_OPERAND_ADDRESS reloads other than the one that uses it. 4127169689Skan This is complicated by the fact that a single operand can have more 4128169689Skan than one RELOAD_FOR_OPERAND_ADDRESS reload. It is very difficult to fix 4129169689Skan choose_reload_regs without affecting code quality, and cases that 4130169689Skan actually fail are extremely rare, so it turns out to be better to fix 4131169689Skan the problem here by not generating cases that choose_reload_regs will 4132169689Skan fail for. */ 4133119256Skan /* There is a similar problem with RELOAD_FOR_INPUT_ADDRESS / 413418334Speter RELOAD_FOR_OUTPUT_ADDRESS when there is more than one of a kind for 413518334Speter a single operand. 413618334Speter We can reduce the register pressure by exploiting that a 413718334Speter RELOAD_FOR_X_ADDR_ADDR that precedes all RELOAD_FOR_X_ADDRESS reloads 4138169689Skan does not conflict with any of them, if it is only used for the first of 4139169689Skan the RELOAD_FOR_X_ADDRESS reloads. */ 414018334Speter { 414118334Speter int first_op_addr_num = -2; 414290075Sobrien int first_inpaddr_num[MAX_RECOG_OPERANDS]; 414390075Sobrien int first_outpaddr_num[MAX_RECOG_OPERANDS]; 414490075Sobrien int need_change = 0; 414550397Sobrien /* We use last_op_addr_reload and the contents of the above arrays 4146169689Skan first as flags - -2 means no instance encountered, -1 means exactly 414718334Speter one instance encountered. 414818334Speter If more than one instance has been encountered, we store the reload 4149132718Skan number of the first reload of the kind in question; reload numbers 4150132718Skan are known to be non-negative. */ 415118334Speter for (i = 0; i < noperands; i++) 415218334Speter first_inpaddr_num[i] = first_outpaddr_num[i] = -2; 415318334Speter for (i = n_reloads - 1; i >= 0; i--) 415490075Sobrien { 415590075Sobrien switch (rld[i].when_needed) 415690075Sobrien { 415790075Sobrien case RELOAD_FOR_OPERAND_ADDRESS: 415890075Sobrien if (++first_op_addr_num >= 0) 4159132718Skan { 416090075Sobrien first_op_addr_num = i; 416190075Sobrien need_change = 1; 4162169689Skan } 4163169689Skan break; 416490075Sobrien case RELOAD_FOR_INPUT_ADDRESS: 416590075Sobrien if (++first_inpaddr_num[rld[i].opnum] >= 0) 416690075Sobrien { 416790075Sobrien first_inpaddr_num[rld[i].opnum] = i; 416890075Sobrien need_change = 1; 416990075Sobrien } 417090075Sobrien break; 417190075Sobrien case RELOAD_FOR_OUTPUT_ADDRESS: 4172169689Skan if (++first_outpaddr_num[rld[i].opnum] >= 0) 417390075Sobrien { 417490075Sobrien first_outpaddr_num[rld[i].opnum] = i; 417590075Sobrien need_change = 1; 417690075Sobrien } 417790075Sobrien break; 417890075Sobrien default: 417990075Sobrien break; 418090075Sobrien } 418190075Sobrien } 418290075Sobrien 418390075Sobrien if (need_change) 4184169689Skan { 4185169689Skan for (i = 0; i < n_reloads; i++) 4186169689Skan { 4187169689Skan int first_num; 418890075Sobrien enum reload_type type; 418990075Sobrien 419090075Sobrien switch (rld[i].when_needed) 419190075Sobrien { 419290075Sobrien case RELOAD_FOR_OPADDR_ADDR: 419390075Sobrien first_num = first_op_addr_num; 419490075Sobrien type = RELOAD_FOR_OPERAND_ADDRESS; 419590075Sobrien break; 419618334Speter case RELOAD_FOR_INPADDR_ADDRESS: 419718334Speter first_num = first_inpaddr_num[rld[i].opnum]; 419818334Speter type = RELOAD_FOR_INPUT_ADDRESS; 4199132718Skan break; 4200132718Skan case RELOAD_FOR_OUTADDR_ADDRESS: 420118334Speter first_num = first_outpaddr_num[rld[i].opnum]; 420290075Sobrien type = RELOAD_FOR_OUTPUT_ADDRESS; 4203169689Skan break; 420490075Sobrien default: 420518334Speter continue; 420618334Speter } 420790075Sobrien if (first_num < 0) 4208132718Skan continue; 420918334Speter else if (i > first_num) 421090075Sobrien rld[i].when_needed = type; 4211169689Skan else 4212169689Skan { 421318334Speter /* Check if the only TYPE reload that uses reload I is 4214169689Skan reload FIRST_NUM. */ 421518334Speter for (j = n_reloads - 1; j > first_num; j--) 421690075Sobrien { 421790075Sobrien if (rld[j].when_needed == type 421818334Speter && (rld[i].secondary_p 421990075Sobrien ? rld[j].secondary_in_reload == i 422090075Sobrien : reg_mentioned_p (rld[i].in, rld[j].in))) 422190075Sobrien { 422218334Speter rld[i].when_needed = type; 422318334Speter break; 422418334Speter } 422518334Speter } 422618334Speter } 422752284Sobrien } 422852284Sobrien } 422952284Sobrien } 423052284Sobrien 423190075Sobrien /* See if we have any reloads that are now allowed to be merged 4232169689Skan because we've changed when the reload is needed to 4233169689Skan RELOAD_FOR_OPERAND_ADDRESS or RELOAD_FOR_OTHER_ADDRESS. Only 4234169689Skan check for the most common cases. */ 423518334Speter 4236169689Skan for (i = 0; i < n_reloads; i++) 423718334Speter if (rld[i].in != 0 && rld[i].out == 0 423818334Speter && (rld[i].when_needed == RELOAD_FOR_OPERAND_ADDRESS 423990075Sobrien || rld[i].when_needed == RELOAD_FOR_OPADDR_ADDR 424090075Sobrien || rld[i].when_needed == RELOAD_FOR_OTHER_ADDRESS)) 424190075Sobrien for (j = 0; j < n_reloads; j++) 424290075Sobrien if (i != j && rld[j].in != 0 && rld[j].out == 0 4243169689Skan && rld[j].when_needed == rld[i].when_needed 4244169689Skan && MATCHES (rld[i].in, rld[j].in) 424518334Speter && rld[i].class == rld[j].class 424690075Sobrien && !rld[i].nocombine && !rld[j].nocombine 4247169689Skan && rld[i].reg_rtx == rld[j].reg_rtx) 424818334Speter { 4249132718Skan rld[i].opnum = MIN (rld[i].opnum, rld[j].opnum); 4250132718Skan transfer_replacements (i, j); 4251132718Skan rld[j].in = 0; 4252169689Skan } 4253169689Skan 4254132718Skan#ifdef HAVE_cc0 4255132718Skan /* If we made any reloads for addresses, see if they violate a 4256132718Skan "no input reloads" requirement for this insn. But loads that we 4257132718Skan do after the insn (such as for output addresses) are fine. */ 425818334Speter if (no_input_reloads) 425918334Speter for (i = 0; i < n_reloads; i++) 426018334Speter if (rld[i].in != 0 426118334Speter && rld[i].when_needed != RELOAD_FOR_OUTADDR_ADDRESS 426250397Sobrien && rld[i].when_needed != RELOAD_FOR_OUTPUT_ADDRESS) 426318334Speter abort (); 426490075Sobrien#endif 426590075Sobrien 426690075Sobrien /* Compute reload_mode and reload_nregs. */ 426790075Sobrien for (i = 0; i < n_reloads; i++) 426850397Sobrien { 426990075Sobrien rld[i].mode 427090075Sobrien = (rld[i].inmode == VOIDmode 427150397Sobrien || (GET_MODE_SIZE (rld[i].outmode) 427250397Sobrien > GET_MODE_SIZE (rld[i].inmode))) 427350397Sobrien ? rld[i].outmode : rld[i].inmode; 427450397Sobrien 427550397Sobrien rld[i].nregs = CLASS_MAX_NREGS (rld[i].class, rld[i].mode); 427650397Sobrien } 427790075Sobrien 427850397Sobrien /* Special case a simple move with an input reload and a 427950397Sobrien destination of a hard reg, if the hard reg is ok, use it. */ 428050397Sobrien for (i = 0; i < n_reloads; i++) 428150397Sobrien if (rld[i].when_needed == RELOAD_FOR_INPUT 428250397Sobrien && GET_CODE (PATTERN (insn)) == SET 428350397Sobrien && GET_CODE (SET_DEST (PATTERN (insn))) == REG 428450397Sobrien && SET_SRC (PATTERN (insn)) == rld[i].in) 428518334Speter { 428618334Speter rtx dest = SET_DEST (PATTERN (insn)); 428790075Sobrien unsigned int regno = REGNO (dest); 428818334Speter 428918334Speter if (regno < FIRST_PSEUDO_REGISTER 429090075Sobrien && TEST_HARD_REG_BIT (reg_class_contents[rld[i].class], regno) 429190075Sobrien && HARD_REGNO_MODE_OK (regno, rld[i].mode)) 429290075Sobrien rld[i].reg_rtx = dest; 429318334Speter } 429490075Sobrien 429590075Sobrien return retval; 429618334Speter} 429718334Speter 429818334Speter/* Return 1 if alternative number ALTNUM in constraint-string CONSTRAINT 429918334Speter accepts a memory operand with constant address. */ 430090075Sobrien 430118334Speterstatic int 430218334Speteralternative_allows_memconst (constraint, altnum) 430318334Speter const char *constraint; 430418334Speter int altnum; 430518334Speter{ 430618334Speter int c; 430718334Speter /* Skip alternatives before the one requested. */ 430890075Sobrien while (altnum > 0) 430918334Speter { 4310169689Skan while (*constraint++ != ','); 431190075Sobrien altnum--; 431290075Sobrien } 431318334Speter /* Scan the requested alternative for 'm' or 'o'. 431418334Speter If one of them is present, this alternative accepts memory constants. */ 431590075Sobrien while ((c = *constraint++) && c != ',' && c != '#') 431690075Sobrien if (c == 'm' || c == 'o') 431790075Sobrien return 1; 431818334Speter return 0; 431918334Speter} 432018334Speter 432190075Sobrien/* Scan X for memory references and scan the addresses for reloading. 432290075Sobrien Also checks for references to "constant" regs that we want to eliminate 432390075Sobrien and replaces them with the values they stand for. 432490075Sobrien We may alter X destructively if it contains a reference to such. 432590075Sobrien If X is just a constant reg, we return the equivalent value 432690075Sobrien instead of X. 432790075Sobrien 432890075Sobrien IND_LEVELS says how many levels of indirect addressing this machine 432990075Sobrien supports. 433090075Sobrien 433118334Speter OPNUM and TYPE identify the purpose of the reload. 433290075Sobrien 433390075Sobrien IS_SET_DEST is true if X is the destination of a SET, which is not 433490075Sobrien appropriate to be replaced by a constant. 4335169689Skan 433618334Speter INSN, if nonzero, is the insn in which we do the reload. It is used 433790075Sobrien to determine if we may generate output reloads, and where to put USEs 433818334Speter for pseudos that we have to replace with stack slots. 433990075Sobrien 434090075Sobrien ADDRESS_RELOADED. If nonzero, is a pointer to where we put the 434190075Sobrien result of find_reloads_address. */ 434290075Sobrien 434318334Speterstatic rtx 434418334Speterfind_reloads_toplev (x, opnum, type, ind_levels, is_set_dest, insn, 434518334Speter address_reloaded) 434690075Sobrien rtx x; 434718334Speter int opnum; 434818334Speter enum reload_type type; 434918334Speter int ind_levels; 435018334Speter int is_set_dest; 435118334Speter rtx insn; 435290075Sobrien int *address_reloaded; 435318334Speter{ 435418334Speter RTX_CODE code = GET_CODE (x); 435518334Speter 435618334Speter const char *fmt = GET_RTX_FORMAT (code); 435718334Speter int i; 4358169689Skan int copied; 435918334Speter 436018334Speter if (code == REG) 436118334Speter { 436218334Speter /* This code is duplicated for speed in find_reloads. */ 436318334Speter int regno = REGNO (x); 436490075Sobrien if (reg_equiv_constant[regno] != 0 && !is_set_dest) 436590075Sobrien x = reg_equiv_constant[regno]; 436690075Sobrien#if 0 436718334Speter /* This creates (subreg (mem...)) which would cause an unnecessary 436818334Speter reload of the mem. */ 436918334Speter else if (reg_equiv_mem[regno] != 0) 437018334Speter x = reg_equiv_mem[regno]; 437118334Speter#endif 437218334Speter else if (reg_equiv_memory_loc[regno] 437318334Speter && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)) 437418334Speter { 437518334Speter rtx mem = make_memloc (x, regno); 437618334Speter if (reg_equiv_address[regno] 437718334Speter || ! rtx_equal_p (mem, reg_equiv_mem[regno])) 437890075Sobrien { 437918334Speter /* If this is not a toplevel operand, find_reloads doesn't see 438018334Speter this substitution. We have to emit a USE of the pseudo so 438118334Speter that delete_output_reload can see it. */ 438218334Speter if (replace_reloads && recog_data.operand[opnum] != x) 438318334Speter /* We mark the USE with QImode so that we recognize it 438418334Speter as one that can be safely deleted at the end of 438518334Speter reload. */ 4386169689Skan PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, x), insn), 438718334Speter QImode); 438818334Speter x = mem; 438918334Speter i = find_reloads_address (GET_MODE (x), &x, XEXP (x, 0), &XEXP (x, 0), 439018334Speter opnum, type, ind_levels, insn); 439118334Speter if (address_reloaded) 439218334Speter *address_reloaded = i; 439318334Speter } 439418334Speter } 439518334Speter return x; 439618334Speter } 439718334Speter if (code == MEM) 439818334Speter { 439918334Speter rtx tem = x; 440018334Speter 440118334Speter i = find_reloads_address (GET_MODE (x), &tem, XEXP (x, 0), &XEXP (x, 0), 440218334Speter opnum, type, ind_levels, insn); 440318334Speter if (address_reloaded) 440418334Speter *address_reloaded = i; 440518334Speter 440618334Speter return tem; 440718334Speter } 440890075Sobrien 440990075Sobrien if (code == SUBREG && GET_CODE (SUBREG_REG (x)) == REG) 441018334Speter { 441118334Speter /* Check for SUBREG containing a REG that's equivalent to a constant. 441218334Speter If the constant has a known value, truncate it right now. 441318334Speter Similarly if we are extracting a single-word of a multi-word 441418334Speter constant. If the constant is symbolic, allow it to be substituted 441590075Sobrien normally. push_reload will strip the subreg later. If the 441618334Speter constant is VOIDmode, abort because we will lose the mode of 441718334Speter the register (this should never happen because one of the cases 441818334Speter above should handle it). */ 441918334Speter 442018334Speter int regno = REGNO (SUBREG_REG (x)); 442118334Speter rtx tem; 442218334Speter 442318334Speter if (subreg_lowpart_p (x) 442418334Speter && regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0 442518334Speter && reg_equiv_constant[regno] != 0 442618334Speter && (tem = gen_lowpart_common (GET_MODE (x), 442718334Speter reg_equiv_constant[regno])) != 0) 442818334Speter return tem; 442918334Speter 443090075Sobrien if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0 443118334Speter && reg_equiv_constant[regno] != 0) 443290075Sobrien { 443390075Sobrien tem = 443490075Sobrien simplify_gen_subreg (GET_MODE (x), reg_equiv_constant[regno], 443518334Speter GET_MODE (SUBREG_REG (x)), SUBREG_BYTE (x)); 443618334Speter if (!tem) 443718334Speter abort (); 443890075Sobrien return tem; 443918334Speter } 444018334Speter 444118334Speter /* If the SUBREG is wider than a word, the above test will fail. 444218334Speter For example, we might have a SImode SUBREG of a DImode SUBREG_REG 444318334Speter for a 16 bit target, or a DImode SUBREG of a TImode SUBREG_REG for 444490075Sobrien a 32 bit target. We still can - and have to - handle this 4445169689Skan for non-paradoxical subregs of CONST_INTs. */ 444618334Speter if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0 4447169689Skan && reg_equiv_constant[regno] != 0 444818334Speter && GET_CODE (reg_equiv_constant[regno]) == CONST_INT 444918334Speter && (GET_MODE_SIZE (GET_MODE (x)) 445018334Speter < GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))))) 445190075Sobrien { 445290075Sobrien int shift = SUBREG_BYTE (x) * BITS_PER_UNIT; 445390075Sobrien if (WORDS_BIG_ENDIAN) 445418334Speter shift = (GET_MODE_BITSIZE (GET_MODE (SUBREG_REG (x))) 445590075Sobrien - GET_MODE_BITSIZE (GET_MODE (x)) 445618334Speter - shift); 445718334Speter /* Here we use the knowledge that CONST_INTs have a 445818334Speter HOST_WIDE_INT field. */ 445918334Speter if (shift >= HOST_BITS_PER_WIDE_INT) 446018334Speter shift = HOST_BITS_PER_WIDE_INT - 1; 446118334Speter return GEN_INT (INTVAL (reg_equiv_constant[regno]) >> shift); 446218334Speter } 446318334Speter 446490075Sobrien if (regno >= FIRST_PSEUDO_REGISTER && reg_renumber[regno] < 0 446590075Sobrien && reg_equiv_constant[regno] != 0 446618334Speter && GET_MODE (reg_equiv_constant[regno]) == VOIDmode) 446790075Sobrien abort (); 446890075Sobrien 446990075Sobrien /* If the subreg contains a reg that will be converted to a mem, 447018334Speter convert the subreg to a narrower memref now. 447118334Speter Otherwise, we would get (subreg (mem ...) ...), 447290075Sobrien which would force reload of the mem. 447318334Speter 447418334Speter We also need to do this if there is an equivalent MEM that is 447550397Sobrien not offsettable. In that case, alter_subreg would produce an 447618334Speter invalid address on big-endian machines. 4477169689Skan 447818334Speter For machines that extend byte loads, we must not reload using 4479169689Skan a wider mode if we have a paradoxical SUBREG. find_reloads will 448018334Speter force a reload in that case. So we should not do anything here. */ 448118334Speter 448218334Speter else if (regno >= FIRST_PSEUDO_REGISTER 448390075Sobrien#ifdef LOAD_EXTEND_OP 448490075Sobrien && (GET_MODE_SIZE (GET_MODE (x)) 448590075Sobrien <= GET_MODE_SIZE (GET_MODE (SUBREG_REG (x)))) 448618334Speter#endif 448790075Sobrien && (reg_equiv_address[regno] != 0 448818334Speter || (reg_equiv_mem[regno] != 0 448918334Speter && (! strict_memory_address_p (GET_MODE (x), 449090075Sobrien XEXP (reg_equiv_mem[regno], 0)) 449118334Speter || ! offsettable_memref_p (reg_equiv_mem[regno]) 449218334Speter || num_not_at_initial_offset)))) 449318334Speter x = find_reloads_subreg_address (x, 1, opnum, type, ind_levels, 449418334Speter insn); 449518334Speter } 449690075Sobrien 449718334Speter for (copied = 0, i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 449818334Speter { 449990075Sobrien if (fmt[i] == 'e') 450018334Speter { 450118334Speter rtx new_part = find_reloads_toplev (XEXP (x, i), opnum, type, 450290075Sobrien ind_levels, is_set_dest, insn, 4503132718Skan address_reloaded); 450418334Speter /* If we have replaced a reg with it's equivalent memory loc - 450518334Speter that can still be handled here e.g. if it's in a paradoxical 450618334Speter subreg - we must make the change in a copy, rather than using 450796263Sobrien a destructive change. This way, find_reloads can still elect 450896263Sobrien not to do the change. */ 4509117395Skan if (new_part != XEXP (x, i) && ! CONSTANT_P (new_part) && ! copied) 451090075Sobrien { 451196263Sobrien x = shallow_copy_rtx (x); 451296263Sobrien copied = 1; 451396263Sobrien } 4514132718Skan XEXP (x, i) = new_part; 451590075Sobrien } 451696263Sobrien } 451790075Sobrien return x; 451896263Sobrien} 4519169689Skan 452096263Sobrien/* Return a mem ref for the memory equivalent of reg REGNO. 452196263Sobrien This mem ref is not shared with anything. */ 452296263Sobrien 452396263Sobrienstatic rtx 4524117395Skanmake_memloc (ad, regno) 452596263Sobrien rtx ad; 452690075Sobrien int regno; 452796263Sobrien{ 4528132718Skan /* We must rerun eliminate_regs, in case the elimination 452918334Speter offsets have changed. */ 453096263Sobrien rtx tem 4531169689Skan = XEXP (eliminate_regs (reg_equiv_memory_loc[regno], 0, NULL_RTX), 0); 4532169689Skan 4533169689Skan /* If TEM might contain a pseudo, we must copy it to avoid 4534169689Skan modifying it when we do the substitution for the reload. */ 4535169689Skan if (rtx_varies_p (tem, 0)) 4536169689Skan tem = copy_rtx (tem); 4537169689Skan 4538169689Skan tem = replace_equiv_address_nv (reg_equiv_memory_loc[regno], tem); 4539169689Skan tem = adjust_address_nv (tem, GET_MODE (ad), 0); 4540169689Skan 4541169689Skan /* Copy the result if it's still the same as the equivalence, to avoid 4542169689Skan modifying it when we do the substitution for the reload. */ 4543169689Skan if (tem == reg_equiv_memory_loc[regno]) 4544169689Skan tem = copy_rtx (tem); 4545169689Skan return tem; 454618334Speter} 454796263Sobrien 454896263Sobrien/* Record all reloads needed for handling memory address AD 454996263Sobrien which appears in *LOC in a memory reference to mode MODE 4550117395Skan which itself is found in location *MEMREFLOC. 455196263Sobrien Note that we take shortcuts assuming that no multi-reg machine mode 455218334Speter occurs as part of an address. 455396263Sobrien 455496263Sobrien OPNUM and TYPE specify the purpose of this reload. 455596263Sobrien 455696263Sobrien IND_LEVELS says how many levels of indirect addressing this machine 4557102780Skan supports. 4558169689Skan 4559169689Skan INSN, if nonzero, is the insn in which we do the reload. It is used 4560102780Skan to determine if we may generate output reloads, and where to put USEs 4561102780Skan for pseudos that we have to replace with stack slots. 4562102780Skan 4563102780Skan Value is nonzero if this address is reloaded or replaced as a whole. 4564102780Skan This is interesting to the caller if the address is an autoincrement. 4565102780Skan 4566169689Skan Note that there is no verification that the address will be valid after 4567169689Skan this routine does its work. Instead, we rely on the fact that the address 4568102780Skan was valid when reload started. So we need only undo things that reload 456996263Sobrien could have broken. These are wrong register types, pseudos not allocated 457096263Sobrien to a hard register, and frame pointer elimination. */ 457196263Sobrien 457296263Sobrienstatic int 457396263Sobrienfind_reloads_address (mode, memrefloc, ad, loc, opnum, type, ind_levels, insn) 457496263Sobrien enum machine_mode mode; 457596263Sobrien rtx *memrefloc; 457696263Sobrien rtx ad; 457796263Sobrien rtx *loc; 457896263Sobrien int opnum; 457996263Sobrien enum reload_type type; 458096263Sobrien int ind_levels; 458196263Sobrien rtx insn; 458296263Sobrien{ 458396263Sobrien int regno; 458452284Sobrien int removed_and = 0; 458596263Sobrien rtx tem; 458696263Sobrien 458796263Sobrien /* If the address is a register, see if it is a legitimate address and 458896263Sobrien reload if not. We first handle the cases where we need not reload 458996263Sobrien or where we must reload in a non-standard way. */ 459096263Sobrien 459196263Sobrien if (GET_CODE (ad) == REG) 459252284Sobrien { 459318334Speter regno = REGNO (ad); 459418334Speter 459518334Speter /* If the register is equivalent to an invariant expression, substitute 459618334Speter the invariant, and eliminate any eliminable register references. */ 4597132718Skan tem = reg_equiv_constant[regno]; 459818334Speter if (tem != 0 459918334Speter && (tem = eliminate_regs (tem, mode, insn)) 4600169689Skan && strict_memory_address_p (mode, tem)) 460196263Sobrien { 4602169689Skan *loc = ad = tem; 460318334Speter return 0; 460496263Sobrien } 460596263Sobrien 460696263Sobrien tem = reg_equiv_memory_loc[regno]; 460796263Sobrien if (tem != 0) 460890075Sobrien { 4609169689Skan if (reg_equiv_address[regno] != 0 || num_not_at_initial_offset) 461090075Sobrien { 461196263Sobrien tem = make_memloc (ad, regno); 461218334Speter if (! strict_memory_address_p (GET_MODE (tem), XEXP (tem, 0))) 461318334Speter { 4614169689Skan find_reloads_address (GET_MODE (tem), (rtx*) 0, XEXP (tem, 0), 4615169689Skan &XEXP (tem, 0), opnum, ADDR_TYPE (type), 461618334Speter ind_levels, insn); 4617132718Skan } 4618169689Skan /* We can avoid a reload if the register's equivalent memory 4619132718Skan expression is valid as an indirect memory address. 462096263Sobrien But not all addresses are valid in a mem used as an indirect 4621169689Skan address: only reg or reg+constant. */ 4622169689Skan 462396263Sobrien if (ind_levels > 0 462496263Sobrien && strict_memory_address_p (mode, tem) 4625169689Skan && (GET_CODE (XEXP (tem, 0)) == REG 462690075Sobrien || (GET_CODE (XEXP (tem, 0)) == PLUS 462790075Sobrien && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG 4628169689Skan && CONSTANT_P (XEXP (XEXP (tem, 0), 1))))) 462996263Sobrien { 463096263Sobrien /* TEM is not the same as what we'll be replacing the 4631169689Skan pseudo with after reload, put a USE in front of INSN 4632169689Skan in the final reload pass. */ 4633169689Skan if (replace_reloads 4634169689Skan && num_not_at_initial_offset 4635169689Skan && ! rtx_equal_p (tem, reg_equiv_mem[regno])) 4636169689Skan { 4637169689Skan *loc = tem; 4638169689Skan /* We mark the USE with QImode so that we 4639169689Skan recognize it as one that can be safely 464090075Sobrien deleted at the end of reload. */ 464190075Sobrien PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad), 464296263Sobrien insn), QImode); 4643169689Skan 4644169689Skan /* This doesn't really count as replacing the address 4645169689Skan as a whole, since it is still a memory access. */ 4646169689Skan } 4647169689Skan return 0; 4648169689Skan } 4649169689Skan ad = tem; 4650169689Skan } 4651169689Skan } 4652169689Skan 4653169689Skan /* The only remaining case where we can avoid a reload is if this is a 4654169689Skan hard register that is valid as a base register and which is not the 4655169689Skan subject of a CLOBBER in this insn. */ 4656169689Skan 4657169689Skan else if (regno < FIRST_PSEUDO_REGISTER 4658169689Skan && REGNO_MODE_OK_FOR_BASE_P (regno, mode) 4659169689Skan && ! regno_clobbered_p (regno, this_insn, mode, 0)) 4660169689Skan return 0; 4661169689Skan 4662169689Skan /* If we do not have one of the cases above, we must do the reload. */ 4663169689Skan push_reload (ad, NULL_RTX, loc, (rtx*) 0, MODE_BASE_REG_CLASS (mode), 4664169689Skan GET_MODE (ad), VOIDmode, 0, 0, opnum, type); 4665169689Skan return 1; 4666169689Skan } 4667169689Skan 4668169689Skan if (strict_memory_address_p (mode, ad)) 4669169689Skan { 4670169689Skan /* The address appears valid, so reloads are not needed. 4671169689Skan But the address may contain an eliminable register. 4672169689Skan This can happen because a machine with indirect addressing 4673169689Skan may consider a pseudo register by itself a valid address even when 4674169689Skan it has failed to get a hard reg. 4675169689Skan So do a tree-walk to find and eliminate all such regs. */ 4676169689Skan 4677169689Skan /* But first quickly dispose of a common case. */ 4678169689Skan if (GET_CODE (ad) == PLUS 4679169689Skan && GET_CODE (XEXP (ad, 1)) == CONST_INT 4680169689Skan && GET_CODE (XEXP (ad, 0)) == REG 4681169689Skan && reg_equiv_constant[REGNO (XEXP (ad, 0))] == 0) 4682169689Skan return 0; 4683169689Skan 4684169689Skan subst_reg_equivs_changed = 0; 4685169689Skan *loc = subst_reg_equivs (ad, insn); 4686169689Skan 4687169689Skan if (! subst_reg_equivs_changed) 4688169689Skan return 0; 4689169689Skan 4690169689Skan /* Check result for validity after substitution. */ 4691169689Skan if (strict_memory_address_p (mode, ad)) 4692169689Skan return 0; 4693169689Skan } 4694169689Skan 4695169689Skan#ifdef LEGITIMIZE_RELOAD_ADDRESS 4696169689Skan do 4697169689Skan { 4698169689Skan if (memrefloc) 4699169689Skan { 4700169689Skan LEGITIMIZE_RELOAD_ADDRESS (ad, GET_MODE (*memrefloc), opnum, type, 4701169689Skan ind_levels, win); 4702169689Skan } 4703169689Skan break; 4704169689Skan win: 4705169689Skan *memrefloc = copy_rtx (*memrefloc); 4706169689Skan XEXP (*memrefloc, 0) = ad; 4707169689Skan move_replacements (&ad, &XEXP (*memrefloc, 0)); 4708169689Skan return 1; 4709169689Skan } 4710169689Skan while (0); 4711169689Skan#endif 4712169689Skan 4713169689Skan /* The address is not valid. We have to figure out why. First see if 4714169689Skan we have an outer AND and remove it if so. Then analyze what's inside. */ 4715169689Skan 4716169689Skan if (GET_CODE (ad) == AND) 4717169689Skan { 4718169689Skan removed_and = 1; 4719169689Skan loc = &XEXP (ad, 0); 4720169689Skan ad = *loc; 472118334Speter } 4722169689Skan 4723169689Skan /* One possibility for why the address is invalid is that it is itself 4724169689Skan a MEM. This can happen when the frame pointer is being eliminated, a 4725169689Skan pseudo is not allocated to a hard register, and the offset between the 4726169689Skan frame and stack pointers is not its initial value. In that case the 4727169689Skan pseudo will have been replaced by a MEM referring to the 4728169689Skan stack pointer. */ 472918334Speter if (GET_CODE (ad) == MEM) 473018334Speter { 473196263Sobrien /* First ensure that the address in this MEM is valid. Then, unless 473296263Sobrien indirect addresses are valid, reload the MEM into a register. */ 473352284Sobrien tem = ad; 4734132718Skan find_reloads_address (GET_MODE (ad), &tem, XEXP (ad, 0), &XEXP (ad, 0), 473552284Sobrien opnum, ADDR_TYPE (type), 473696263Sobrien ind_levels == 0 ? 0 : ind_levels - 1, insn); 473790075Sobrien 473896263Sobrien /* If tem was changed, then we must create a new memory reference to 473996263Sobrien hold it and store it back into memrefloc. */ 474052284Sobrien if (tem != ad && memrefloc) 474196263Sobrien { 474296263Sobrien *memrefloc = copy_rtx (*memrefloc); 474396263Sobrien copy_replacements (tem, XEXP (*memrefloc, 0)); 474496263Sobrien loc = &XEXP (*memrefloc, 0); 474596263Sobrien if (removed_and) 474696263Sobrien loc = &XEXP (*loc, 0); 474796263Sobrien } 474896263Sobrien 474996263Sobrien /* Check similar cases as for indirect addresses as above except 475096263Sobrien that we can allow pseudos and a MEM since they should have been 475196263Sobrien taken care of above. */ 475296263Sobrien 475396263Sobrien if (ind_levels == 0 475496263Sobrien || (GET_CODE (XEXP (tem, 0)) == SYMBOL_REF && ! indirect_symref_ok) 475596263Sobrien || GET_CODE (XEXP (tem, 0)) == MEM 475696263Sobrien || ! (GET_CODE (XEXP (tem, 0)) == REG 475796263Sobrien || (GET_CODE (XEXP (tem, 0)) == PLUS 4758169689Skan && GET_CODE (XEXP (XEXP (tem, 0), 0)) == REG 4759169689Skan && GET_CODE (XEXP (XEXP (tem, 0), 1)) == CONST_INT))) 4760169689Skan { 4761169689Skan /* Must use TEM here, not AD, since it is the one that will 4762169689Skan have any subexpressions reloaded, if needed. */ 4763169689Skan push_reload (tem, NULL_RTX, loc, (rtx*) 0, 4764169689Skan MODE_BASE_REG_CLASS (mode), GET_MODE (tem), 4765169689Skan VOIDmode, 0, 4766169689Skan 0, opnum, type); 4767169689Skan return ! removed_and; 4768169689Skan } 4769169689Skan else 477096263Sobrien return 0; 477152284Sobrien } 4772169689Skan 4773169689Skan /* If we have address of a stack slot but it's not valid because the 4774169689Skan displacement is too large, compute the sum in a register. 477596263Sobrien Handle all base registers here, not just fp/ap/sp, because on some 477696263Sobrien targets (namely SH) we can also get too large displacements from 4777169689Skan big-endian corrections. */ 477852284Sobrien else if (GET_CODE (ad) == PLUS 477952284Sobrien && GET_CODE (XEXP (ad, 0)) == REG 4780169689Skan && REGNO (XEXP (ad, 0)) < FIRST_PSEUDO_REGISTER 4781169689Skan && REG_MODE_OK_FOR_BASE_P (XEXP (ad, 0), mode) 4782169689Skan && GET_CODE (XEXP (ad, 1)) == CONST_INT) 4783169689Skan { 4784169689Skan /* Unshare the MEM rtx so we can safely alter it. */ 4785146895Skan if (memrefloc) 4786146895Skan { 4787146895Skan *memrefloc = copy_rtx (*memrefloc); 4788169689Skan loc = &XEXP (*memrefloc, 0); 4789146895Skan if (removed_and) 4790169689Skan loc = &XEXP (*loc, 0); 4791169689Skan } 4792169689Skan 4793146895Skan if (double_reg_address_ok) 4794169689Skan { 4795169689Skan /* Unshare the sum as well. */ 4796169689Skan *loc = ad = copy_rtx (ad); 4797169689Skan 4798169689Skan /* Reload the displacement into an index reg. 4799169689Skan We assume the frame pointer or arg pointer is a base reg. */ 4800169689Skan find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1), 4801169689Skan INDEX_REG_CLASS, GET_MODE (ad), opnum, 4802169689Skan type, ind_levels); 4803169689Skan return 0; 4804169689Skan } 4805169689Skan else 4806169689Skan { 4807169689Skan /* If the sum of two regs is not necessarily valid, 4808169689Skan reload the sum into a base reg. 4809169689Skan That will at least work. */ 4810169689Skan find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode), 4811169689Skan Pmode, opnum, type, ind_levels); 4812169689Skan } 4813169689Skan return ! removed_and; 4814169689Skan } 4815169689Skan 4816169689Skan /* If we have an indexed stack slot, there are three possible reasons why 4817169689Skan it might be invalid: The index might need to be reloaded, the address 4818169689Skan might have been made by frame pointer elimination and hence have a 4819169689Skan constant out of range, or both reasons might apply. 4820169689Skan 4821169689Skan We can easily check for an index needing reload, but even if that is the 4822169689Skan case, we might also have an invalid constant. To avoid making the 4823169689Skan conservative assumption and requiring two reloads, we see if this address 4824169689Skan is valid when not interpreted strictly. If it is, the only problem is 4825169689Skan that the index needs a reload and find_reloads_address_1 will take care 4826169689Skan of it. 4827169689Skan 4828169689Skan If we decide to do something here, it must be that 4829169689Skan `double_reg_address_ok' is true and that this address rtl was made by 4830169689Skan eliminate_regs. We generate a reload of the fp/sp/ap + constant and 4831169689Skan rework the sum so that the reload register will be added to the index. 4832169689Skan This is safe because we know the address isn't shared. 4833169689Skan 4834169689Skan We check for fp/ap/sp as both the first and second operand of the 4835169689Skan innermost PLUS. */ 4836169689Skan 4837169689Skan else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT 4838146895Skan && GET_CODE (XEXP (ad, 0)) == PLUS 4839146895Skan && (XEXP (XEXP (ad, 0), 0) == frame_pointer_rtx 4840146895Skan#if FRAME_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM 4841146895Skan || XEXP (XEXP (ad, 0), 0) == hard_frame_pointer_rtx 4842146895Skan#endif 4843169689Skan#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM 4844146895Skan || XEXP (XEXP (ad, 0), 0) == arg_pointer_rtx 4845169689Skan#endif 4846169689Skan || XEXP (XEXP (ad, 0), 0) == stack_pointer_rtx) 4847169689Skan && ! memory_address_p (mode, ad)) 4848169689Skan { 4849169689Skan *loc = ad = gen_rtx_PLUS (GET_MODE (ad), 4850169689Skan plus_constant (XEXP (XEXP (ad, 0), 0), 4851169689Skan INTVAL (XEXP (ad, 1))), 4852169689Skan XEXP (XEXP (ad, 0), 1)); 4853169689Skan find_reloads_address_part (XEXP (ad, 0), &XEXP (ad, 0), 4854169689Skan MODE_BASE_REG_CLASS (mode), 4855169689Skan GET_MODE (ad), opnum, type, ind_levels); 4856169689Skan find_reloads_address_1 (mode, XEXP (ad, 1), 1, &XEXP (ad, 1), opnum, 4857169689Skan type, 0, insn); 4858169689Skan 4859169689Skan return 0; 4860169689Skan } 4861169689Skan 4862169689Skan else if (GET_CODE (ad) == PLUS && GET_CODE (XEXP (ad, 1)) == CONST_INT 4863169689Skan && GET_CODE (XEXP (ad, 0)) == PLUS 4864169689Skan && (XEXP (XEXP (ad, 0), 1) == frame_pointer_rtx 4865169689Skan#if HARD_FRAME_POINTER_REGNUM != FRAME_POINTER_REGNUM 4866169689Skan || XEXP (XEXP (ad, 0), 1) == hard_frame_pointer_rtx 4867169689Skan#endif 4868169689Skan#if FRAME_POINTER_REGNUM != ARG_POINTER_REGNUM 4869169689Skan || XEXP (XEXP (ad, 0), 1) == arg_pointer_rtx 4870169689Skan#endif 4871169689Skan || XEXP (XEXP (ad, 0), 1) == stack_pointer_rtx) 4872169689Skan && ! memory_address_p (mode, ad)) 4873169689Skan { 4874169689Skan *loc = ad = gen_rtx_PLUS (GET_MODE (ad), 4875169689Skan XEXP (XEXP (ad, 0), 0), 4876169689Skan plus_constant (XEXP (XEXP (ad, 0), 1), 4877169689Skan INTVAL (XEXP (ad, 1)))); 4878169689Skan find_reloads_address_part (XEXP (ad, 1), &XEXP (ad, 1), 4879169689Skan MODE_BASE_REG_CLASS (mode), 4880169689Skan GET_MODE (ad), opnum, type, ind_levels); 4881169689Skan find_reloads_address_1 (mode, XEXP (ad, 0), 1, &XEXP (ad, 0), opnum, 4882146895Skan type, 0, insn); 4883169689Skan 4884146895Skan return 0; 4885146895Skan } 4886146895Skan 4887169689Skan /* See if address becomes valid when an eliminable register 4888169689Skan in a sum is replaced. */ 4889169689Skan 4890169689Skan tem = ad; 4891169689Skan if (GET_CODE (ad) == PLUS) 4892169689Skan tem = subst_indexed_address (ad); 4893169689Skan if (tem != ad && strict_memory_address_p (mode, tem)) 4894169689Skan { 4895169689Skan /* Ok, we win that way. Replace any additional eliminable 4896169689Skan registers. */ 4897169689Skan 4898169689Skan subst_reg_equivs_changed = 0; 4899169689Skan tem = subst_reg_equivs (tem, insn); 4900169689Skan 4901169689Skan /* Make sure that didn't make the address invalid again. */ 4902169689Skan 4903169689Skan if (! subst_reg_equivs_changed || strict_memory_address_p (mode, tem)) 4904169689Skan { 4905169689Skan *loc = tem; 4906169689Skan return 0; 4907169689Skan } 4908169689Skan } 4909169689Skan 4910169689Skan /* If constants aren't valid addresses, reload the constant address 4911169689Skan into a register. */ 4912169689Skan if (CONSTANT_P (ad) && ! strict_memory_address_p (mode, ad)) 4913169689Skan { 4914169689Skan /* If AD is an address in the constant pool, the MEM rtx may be shared. 4915169689Skan Unshare it so we can safely alter it. */ 4916169689Skan if (memrefloc && GET_CODE (ad) == SYMBOL_REF 4917169689Skan && CONSTANT_POOL_ADDRESS_P (ad)) 4918146895Skan { 4919146895Skan *memrefloc = copy_rtx (*memrefloc); 4920146895Skan loc = &XEXP (*memrefloc, 0); 4921169689Skan if (removed_and) 4922169689Skan loc = &XEXP (*loc, 0); 4923146895Skan } 4924146895Skan 4925169689Skan find_reloads_address_part (ad, loc, MODE_BASE_REG_CLASS (mode), 4926146895Skan Pmode, opnum, type, ind_levels); 4927169689Skan return ! removed_and; 4928169689Skan } 4929146895Skan 4930169689Skan return find_reloads_address_1 (mode, ad, 0, loc, opnum, type, ind_levels, 4931169689Skan insn); 4932169689Skan} 4933146895Skan 4934169689Skan/* Find all pseudo regs appearing in AD 4935169689Skan that are eliminable in favor of equivalent values 4936169689Skan and do not have hard regs; replace them by their equivalents. 4937169689Skan INSN, if nonzero, is the insn in which we do the reload. We put USEs in 4938169689Skan front of it for pseudos that we have to replace with stack slots. */ 4939169689Skan 4940169689Skanstatic rtx 4941169689Skansubst_reg_equivs (ad, insn) 4942169689Skan rtx ad; 4943169689Skan rtx insn; 4944169689Skan{ 4945146895Skan RTX_CODE code = GET_CODE (ad); 4946169689Skan int i; 4947146895Skan const char *fmt; 4948169689Skan 4949169689Skan switch (code) 4950169689Skan { 4951169689Skan case HIGH: 4952169689Skan case CONST_INT: 4953169689Skan case CONST: 4954169689Skan case CONST_DOUBLE: 4955169689Skan case CONST_VECTOR: 4956169689Skan case SYMBOL_REF: 4957169689Skan case LABEL_REF: 4958169689Skan case PC: 4959169689Skan case CC0: 4960169689Skan return ad; 4961169689Skan 4962146895Skan case REG: 4963146895Skan { 496490075Sobrien int regno = REGNO (ad); 496590075Sobrien 496690075Sobrien if (reg_equiv_constant[regno] != 0) 496718334Speter { 4968169689Skan subst_reg_equivs_changed = 1; 496918334Speter return reg_equiv_constant[regno]; 4970169689Skan } 4971169689Skan if (reg_equiv_memory_loc[regno] && num_not_at_initial_offset) 497218334Speter { 4973169689Skan rtx mem = make_memloc (ad, regno); 4974117395Skan if (! rtx_equal_p (mem, reg_equiv_mem[regno])) 4975169689Skan { 497618334Speter subst_reg_equivs_changed = 1; 4977169689Skan /* We mark the USE with QImode so that we recognize it 4978146895Skan as one that can be safely deleted at the end of 4979169689Skan reload. */ 4980169689Skan PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, ad), insn), 4981169689Skan QImode); 4982169689Skan return mem; 4983169689Skan } 4984169689Skan } 4985169689Skan } 4986169689Skan return ad; 4987169689Skan 4988169689Skan case PLUS: 4989169689Skan /* Quickly dispose of a common case. */ 4990169689Skan if (XEXP (ad, 0) == frame_pointer_rtx 4991169689Skan && GET_CODE (XEXP (ad, 1)) == CONST_INT) 4992146895Skan return ad; 4993146895Skan break; 4994132718Skan 4995169689Skan default: 4996169689Skan break; 4997169689Skan } 4998169689Skan 4999169689Skan fmt = GET_RTX_FORMAT (code); 5000169689Skan for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 5001169689Skan if (fmt[i] == 'e') 5002169689Skan XEXP (ad, i) = subst_reg_equivs (XEXP (ad, i), insn); 5003169689Skan return ad; 5004169689Skan} 5005169689Skan 500696263Sobrien/* Compute the sum of X and Y, making canonicalizations assumed in an 5007132718Skan address, namely: sum constant integers, surround the sum of two 5008169689Skan constants with a CONST, put the constant as the second operand, and 5009169689Skan group the constant on the outermost sum. 5010169689Skan 5011169689Skan This routine assumes both inputs are already in canonical form. */ 5012169689Skan 5013169689Skanrtx 5014169689Skanform_sum (x, y) 5015169689Skan rtx x, y; 5016169689Skan{ 5017169689Skan rtx tem; 5018169689Skan enum machine_mode mode = GET_MODE (x); 5019169689Skan 5020169689Skan if (mode == VOIDmode) 5021169689Skan mode = GET_MODE (y); 5022169689Skan 5023132718Skan if (mode == VOIDmode) 5024169689Skan mode = Pmode; 5025132718Skan 5026169689Skan if (GET_CODE (x) == CONST_INT) 5027169689Skan return plus_constant (y, INTVAL (x)); 5028169689Skan else if (GET_CODE (y) == CONST_INT) 5029169689Skan return plus_constant (x, INTVAL (y)); 5030169689Skan else if (CONSTANT_P (x)) 5031169689Skan tem = x, x = y, y = tem; 5032169689Skan 5033169689Skan if (GET_CODE (x) == PLUS && CONSTANT_P (XEXP (x, 1))) 5034169689Skan return form_sum (XEXP (x, 0), form_sum (XEXP (x, 1), y)); 5035169689Skan 5036169689Skan /* Note that if the operands of Y are specified in the opposite 503718334Speter order in the recursive calls below, infinite recursion will occur. */ 503850397Sobrien if (GET_CODE (y) == PLUS && CONSTANT_P (XEXP (y, 1))) 5039117395Skan return form_sum (form_sum (x, XEXP (y, 0)), XEXP (y, 1)); 5040117395Skan 5041117395Skan /* If both constant, encapsulate sum. Otherwise, just form sum. A 5042117395Skan constant will have been placed second. */ 5043132718Skan if (CONSTANT_P (x) && CONSTANT_P (y)) 5044117395Skan { 5045117395Skan if (GET_CODE (x) == CONST) 5046169689Skan x = XEXP (x, 0); 5047117395Skan if (GET_CODE (y) == CONST) 5048117395Skan y = XEXP (y, 0); 5049117395Skan 5050117395Skan return gen_rtx_CONST (VOIDmode, gen_rtx_PLUS (mode, x, y)); 5051169689Skan } 5052117395Skan 5053117395Skan return gen_rtx_PLUS (mode, x, y); 5054117395Skan} 5055117395Skan 5056117395Skan/* If ADDR is a sum containing a pseudo register that should be 5057117395Skan replaced with a constant (from reg_equiv_constant), 5058117395Skan return the result of doing so, and also apply the associative 5059169689Skan law so that the result is more likely to be a valid address. 5060169689Skan (But it is not guaranteed to be one.) 5061117395Skan 5062117395Skan Note that at most one register is replaced, even if more are 5063117395Skan replaceable. Also, we try to put the result into a canonical form 5064117395Skan so it is more likely to be a valid address. 5065117395Skan 5066215840Sdim In all other cases, return ADDR. */ 5067132718Skan 5068117395Skanstatic rtx 5069132718Skansubst_indexed_address (addr) 5070117395Skan rtx addr; 5071117395Skan{ 5072215840Sdim rtx op0 = 0, op1 = 0, op2 = 0; 5073215840Sdim rtx tem; 5074215840Sdim int regno; 5075215840Sdim 5076215840Sdim if (GET_CODE (addr) == PLUS) 5077215840Sdim { 5078117395Skan /* Try to find a register to replace. */ 5079117395Skan op0 = XEXP (addr, 0), op1 = XEXP (addr, 1), op2 = 0; 508050397Sobrien if (GET_CODE (op0) == REG 508150397Sobrien && (regno = REGNO (op0)) >= FIRST_PSEUDO_REGISTER 508250397Sobrien && reg_renumber[regno] < 0 508350397Sobrien && reg_equiv_constant[regno] != 0) 508450397Sobrien op0 = reg_equiv_constant[regno]; 508550397Sobrien else if (GET_CODE (op1) == REG 5086132718Skan && (regno = REGNO (op1)) >= FIRST_PSEUDO_REGISTER 508750397Sobrien && reg_renumber[regno] < 0 508850397Sobrien && reg_equiv_constant[regno] != 0) 508950397Sobrien op1 = reg_equiv_constant[regno]; 509050397Sobrien else if (GET_CODE (op0) == PLUS 509150397Sobrien && (tem = subst_indexed_address (op0)) != op0) 509250397Sobrien op0 = tem; 509350397Sobrien else if (GET_CODE (op1) == PLUS 509450397Sobrien && (tem = subst_indexed_address (op1)) != op1) 509550397Sobrien op1 = tem; 509650397Sobrien else 5097132718Skan return addr; 509850397Sobrien 5099169689Skan /* Pick out up to three things to add. */ 5100169689Skan if (GET_CODE (op1) == PLUS) 510150397Sobrien op2 = XEXP (op1, 1), op1 = XEXP (op1, 0); 510250397Sobrien else if (GET_CODE (op0) == PLUS) 510350397Sobrien op2 = op1, op1 = XEXP (op0, 1), op0 = XEXP (op0, 0); 5104132718Skan 510550397Sobrien /* Compute the sum. */ 510650397Sobrien if (op2 != 0) 510750397Sobrien op1 = form_sum (op1, op2); 510850397Sobrien if (op1 != 0) 510950397Sobrien op0 = form_sum (op0, op1); 511050397Sobrien 5111132718Skan return op0; 5112132718Skan } 5113132718Skan return addr; 511450397Sobrien} 5115169689Skan 5116169689Skan/* Update the REG_INC notes for an insn. It updates all REG_INC 5117169689Skan notes for the instruction which refer to REGNO the to refer 5118169689Skan to the reload number. 511950397Sobrien 512090075Sobrien INSN is the insn for which any REG_INC notes need updating. 512190075Sobrien 5122132718Skan REGNO is the register number which has been reloaded. 512390075Sobrien 5124169689Skan RELOADNUM is the reload number. */ 5125169689Skan 5126169689Skanstatic void 5127169689Skanupdate_auto_inc_notes (insn, regno, reloadnum) 5128132718Skan rtx insn ATTRIBUTE_UNUSED; 5129132718Skan int regno ATTRIBUTE_UNUSED; 513090075Sobrien int reloadnum ATTRIBUTE_UNUSED; 513190075Sobrien{ 5132169689Skan#ifdef AUTO_INC_DEC 5133169689Skan rtx link; 5134169689Skan 5135169689Skan for (link = REG_NOTES (insn); link; link = XEXP (link, 1)) 5136169689Skan if (REG_NOTE_KIND (link) == REG_INC 5137169689Skan && REGNO (XEXP (link, 0)) == regno) 5138169689Skan push_replacement (&XEXP (link, 0), reloadnum, VOIDmode); 5139169689Skan#endif 5140169689Skan} 5141169689Skan 5142169689Skan/* Record the pseudo registers we must reload into hard registers in a 5143169689Skan subexpression of a would-be memory address, X referring to a value 5144169689Skan in mode MODE. (This function is not called if the address we find 5145169689Skan is strictly valid.) 5146169689Skan 5147169689Skan CONTEXT = 1 means we are considering regs as index regs, 5148169689Skan = 0 means we are considering them as base regs. 5149169689Skan 5150169689Skan OPNUM and TYPE specify the purpose of any reloads made. 5151169689Skan 5152169689Skan IND_LEVELS says how many levels of indirect addressing are 5153169689Skan supported at this point in the address. 5154169689Skan 5155169689Skan INSN, if nonzero, is the insn in which we do the reload. It is used 5156169689Skan to determine if we may generate output reloads. 5157169689Skan 5158169689Skan We return nonzero if X, as a whole, is reloaded or replaced. */ 5159169689Skan 5160169689Skan/* Note that we take shortcuts assuming that no multi-reg machine mode 5161169689Skan occurs as part of an address. 5162169689Skan Also, this is not fully machine-customizable; it works for machines 5163169689Skan such as VAXen and 68000's and 32000's, but other possible machines 5164169689Skan could have addressing modes that this does not handle right. */ 5165169689Skan 5166169689Skanstatic int 5167169689Skanfind_reloads_address_1 (mode, x, context, loc, opnum, type, ind_levels, insn) 5168169689Skan enum machine_mode mode; 5169169689Skan rtx x; 5170169689Skan int context; 5171169689Skan rtx *loc; 5172169689Skan int opnum; 5173169689Skan enum reload_type type; 5174169689Skan int ind_levels; 5175169689Skan rtx insn; 5176169689Skan{ 5177169689Skan RTX_CODE code = GET_CODE (x); 5178169689Skan 5179169689Skan switch (code) 5180169689Skan { 5181169689Skan case PLUS: 5182169689Skan { 5183169689Skan rtx orig_op0 = XEXP (x, 0); 5184169689Skan rtx orig_op1 = XEXP (x, 1); 5185169689Skan RTX_CODE code0 = GET_CODE (orig_op0); 5186169689Skan RTX_CODE code1 = GET_CODE (orig_op1); 5187169689Skan rtx op0 = orig_op0; 5188169689Skan rtx op1 = orig_op1; 5189169689Skan 5190169689Skan if (GET_CODE (op0) == SUBREG) 5191169689Skan { 519290075Sobrien op0 = SUBREG_REG (op0); 519390075Sobrien code0 = GET_CODE (op0); 5194117395Skan if (code0 == REG && REGNO (op0) < FIRST_PSEUDO_REGISTER) 5195169689Skan op0 = gen_rtx_REG (word_mode, 5196117395Skan (REGNO (op0) + 5197117395Skan subreg_regno_offset (REGNO (SUBREG_REG (orig_op0)), 5198117395Skan GET_MODE (SUBREG_REG (orig_op0)), 5199117395Skan SUBREG_BYTE (orig_op0), 5200169689Skan GET_MODE (orig_op0)))); 5201169689Skan } 5202117395Skan 5203117395Skan if (GET_CODE (op1) == SUBREG) 5204117395Skan { 5205117395Skan op1 = SUBREG_REG (op1); 5206117395Skan code1 = GET_CODE (op1); 5207117395Skan if (code1 == REG && REGNO (op1) < FIRST_PSEUDO_REGISTER) 5208169689Skan /* ??? Why is this given op1's mode and above for 5209117395Skan ??? op0 SUBREGs we use word_mode? */ 5210117395Skan op1 = gen_rtx_REG (GET_MODE (op1), 5211117395Skan (REGNO (op1) + 5212117395Skan subreg_regno_offset (REGNO (SUBREG_REG (orig_op1)), 5213117395Skan GET_MODE (SUBREG_REG (orig_op1)), 5214117395Skan SUBREG_BYTE (orig_op1), 5215117395Skan GET_MODE (orig_op1)))); 5216117395Skan } 5217117395Skan 5218117395Skan if (code0 == MULT || code0 == SIGN_EXTEND || code0 == TRUNCATE 5219117395Skan || code0 == ZERO_EXTEND || code1 == MEM) 5220117395Skan { 522190075Sobrien find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum, 522290075Sobrien type, ind_levels, insn); 522390075Sobrien find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum, 522490075Sobrien type, ind_levels, insn); 522590075Sobrien } 522690075Sobrien 522790075Sobrien else if (code1 == MULT || code1 == SIGN_EXTEND || code1 == TRUNCATE 522890075Sobrien || code1 == ZERO_EXTEND || code0 == MEM) 5229132718Skan { 523090075Sobrien find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum, 523190075Sobrien type, ind_levels, insn); 523290075Sobrien find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum, 523390075Sobrien type, ind_levels, insn); 523490075Sobrien } 5235169689Skan 523690075Sobrien else if (code0 == CONST_INT || code0 == CONST 5237169689Skan || code0 == SYMBOL_REF || code0 == LABEL_REF) 5238169689Skan find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum, 5239169689Skan type, ind_levels, insn); 5240169689Skan 5241169689Skan else if (code1 == CONST_INT || code1 == CONST 5242169689Skan || code1 == SYMBOL_REF || code1 == LABEL_REF) 5243169689Skan find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum, 5244169689Skan type, ind_levels, insn); 5245169689Skan 524690075Sobrien else if (code0 == REG && code1 == REG) 524790075Sobrien { 524890075Sobrien if (REG_OK_FOR_INDEX_P (op0) 524990075Sobrien && REG_MODE_OK_FOR_BASE_P (op1, mode)) 525090075Sobrien return 0; 525190075Sobrien else if (REG_OK_FOR_INDEX_P (op1) 5252169689Skan && REG_MODE_OK_FOR_BASE_P (op0, mode)) 5253117395Skan return 0; 5254117395Skan else if (REG_MODE_OK_FOR_BASE_P (op1, mode)) 525590075Sobrien find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum, 525690075Sobrien type, ind_levels, insn); 525790075Sobrien else if (REG_MODE_OK_FOR_BASE_P (op0, mode)) 525890075Sobrien find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum, 525990075Sobrien type, ind_levels, insn); 5260169689Skan else if (REG_OK_FOR_INDEX_P (op1)) 526190075Sobrien find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum, 526290075Sobrien type, ind_levels, insn); 5263117395Skan else if (REG_OK_FOR_INDEX_P (op0)) 5264169689Skan find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum, 5265169689Skan type, ind_levels, insn); 5266117395Skan else 5267117395Skan { 5268169689Skan find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum, 5269169689Skan type, ind_levels, insn); 5270169689Skan find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum, 5271169689Skan type, ind_levels, insn); 5272169689Skan } 5273117395Skan } 5274117395Skan 5275117395Skan else if (code0 == REG) 5276117395Skan { 5277117395Skan find_reloads_address_1 (mode, orig_op0, 1, &XEXP (x, 0), opnum, 5278117395Skan type, ind_levels, insn); 5279117395Skan find_reloads_address_1 (mode, orig_op1, 0, &XEXP (x, 1), opnum, 5280117395Skan type, ind_levels, insn); 5281117395Skan } 5282117395Skan 5283117395Skan else if (code1 == REG) 528490075Sobrien { 528590075Sobrien find_reloads_address_1 (mode, orig_op1, 1, &XEXP (x, 1), opnum, 528690075Sobrien type, ind_levels, insn); 5287169689Skan find_reloads_address_1 (mode, orig_op0, 0, &XEXP (x, 0), opnum, 5288169689Skan type, ind_levels, insn); 5289169689Skan } 5290169689Skan } 5291169689Skan 5292169689Skan return 0; 5293169689Skan 5294169689Skan case POST_MODIFY: 5295169689Skan case PRE_MODIFY: 5296169689Skan { 529790075Sobrien rtx op0 = XEXP (x, 0); 529890075Sobrien rtx op1 = XEXP (x, 1); 529990075Sobrien 530090075Sobrien if (GET_CODE (op1) != PLUS && GET_CODE (op1) != MINUS) 5301132718Skan return 0; 5302169689Skan 5303169689Skan /* Currently, we only support {PRE,POST}_MODIFY constructs 530490075Sobrien where a base register is {inc,dec}remented by the contents 530590075Sobrien of another register or by a constant value. Thus, these 530690075Sobrien operands must match. */ 5307169689Skan if (op0 != XEXP (op1, 0)) 530890075Sobrien abort (); 530990075Sobrien 531090075Sobrien /* Require index register (or constant). Let's just handle the 5311169689Skan register case in the meantime... If the target allows 5312169689Skan auto-modify by a constant then we could try replacing a pseudo 531390075Sobrien register with its equivalent constant where applicable. */ 531490075Sobrien if (REG_P (XEXP (op1, 1))) 531590075Sobrien if (!REGNO_OK_FOR_INDEX_P (REGNO (XEXP (op1, 1)))) 5316169689Skan find_reloads_address_1 (mode, XEXP (op1, 1), 1, &XEXP (op1, 1), 5317169689Skan opnum, type, ind_levels, insn); 5318169689Skan 5319169689Skan if (REG_P (XEXP (op1, 0))) 5320169689Skan { 5321169689Skan int regno = REGNO (XEXP (op1, 0)); 532290075Sobrien int reloadnum; 532390075Sobrien 532490075Sobrien /* A register that is incremented cannot be constant! */ 532590075Sobrien if (regno >= FIRST_PSEUDO_REGISTER 532690075Sobrien && reg_equiv_constant[regno] != 0) 532790075Sobrien abort (); 532890075Sobrien 532990075Sobrien /* Handle a register that is equivalent to a memory location 533090075Sobrien which cannot be addressed directly. */ 533190075Sobrien if (reg_equiv_memory_loc[regno] != 0 533290075Sobrien && (reg_equiv_address[regno] != 0 533390075Sobrien || num_not_at_initial_offset)) 533490075Sobrien { 533590075Sobrien rtx tem = make_memloc (XEXP (x, 0), regno); 533690075Sobrien 533790075Sobrien if (reg_equiv_address[regno] 533890075Sobrien || ! rtx_equal_p (tem, reg_equiv_mem[regno])) 5339117395Skan { 5340117395Skan /* First reload the memory location's address. 5341169689Skan We can't use ADDR_TYPE (type) here, because we need to 5342169689Skan write back the value after reading it, hence we actually 534390075Sobrien need two registers. */ 534490075Sobrien find_reloads_address (GET_MODE (tem), 0, XEXP (tem, 0), 5345117395Skan &XEXP (tem, 0), opnum, 534690075Sobrien RELOAD_OTHER, 5347117395Skan ind_levels, insn); 5348117395Skan 5349117395Skan /* Then reload the memory location into a base 5350169689Skan register. */ 5351117395Skan reloadnum = push_reload (tem, tem, &XEXP (x, 0), 5352117395Skan &XEXP (op1, 0), 5353117395Skan MODE_BASE_REG_CLASS (mode), 5354117395Skan GET_MODE (x), GET_MODE (x), 0, 5355117395Skan 0, opnum, RELOAD_OTHER); 5356117395Skan 5357169689Skan update_auto_inc_notes (this_insn, regno, reloadnum); 5358169689Skan return 0; 5359169689Skan } 5360169689Skan } 5361169689Skan 5362169689Skan if (reg_renumber[regno] >= 0) 5363169689Skan regno = reg_renumber[regno]; 5364169689Skan 5365117395Skan /* We require a base register here... */ 5366117395Skan if (!REGNO_MODE_OK_FOR_BASE_P (regno, GET_MODE (x))) 5367117395Skan { 5368169689Skan reloadnum = push_reload (XEXP (op1, 0), XEXP (x, 0), 5369169689Skan &XEXP (op1, 0), &XEXP (x, 0), 5370169689Skan MODE_BASE_REG_CLASS (mode), 5371117395Skan GET_MODE (x), GET_MODE (x), 0, 0, 5372117395Skan opnum, RELOAD_OTHER); 5373117395Skan 537490075Sobrien update_auto_inc_notes (this_insn, regno, reloadnum); 537590075Sobrien return 0; 537690075Sobrien } 5377169689Skan } 5378169689Skan else 537990075Sobrien abort (); 538090075Sobrien } 538190075Sobrien return 0; 538290075Sobrien 538390075Sobrien case POST_INC: 538490075Sobrien case POST_DEC: 538590075Sobrien case PRE_INC: 538690075Sobrien case PRE_DEC: 538790075Sobrien if (GET_CODE (XEXP (x, 0)) == REG) 538890075Sobrien { 538990075Sobrien int regno = REGNO (XEXP (x, 0)); 539090075Sobrien int value = 0; 539190075Sobrien rtx x_orig = x; 5392169689Skan 5393169689Skan /* A register that is incremented cannot be constant! */ 539490075Sobrien if (regno >= FIRST_PSEUDO_REGISTER 5395169689Skan && reg_equiv_constant[regno] != 0) 539690075Sobrien abort (); 539790075Sobrien 539890075Sobrien /* Handle a register that is equivalent to a memory location 539990075Sobrien which cannot be addressed directly. */ 540090075Sobrien if (reg_equiv_memory_loc[regno] != 0 540190075Sobrien && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)) 540290075Sobrien { 540390075Sobrien rtx tem = make_memloc (XEXP (x, 0), regno); 540490075Sobrien if (reg_equiv_address[regno] 540590075Sobrien || ! rtx_equal_p (tem, reg_equiv_mem[regno])) 540690075Sobrien { 5407117395Skan /* First reload the memory location's address. 5408117395Skan We can't use ADDR_TYPE (type) here, because we need to 5409169689Skan write back the value after reading it, hence we actually 5410132718Skan need two registers. */ 5411132718Skan find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0), 5412117395Skan &XEXP (tem, 0), opnum, type, 5413117395Skan ind_levels, insn); 5414117395Skan /* Put this inside a new increment-expression. */ 5415117395Skan x = gen_rtx_fmt_e (GET_CODE (x), GET_MODE (x), tem); 5416169689Skan /* Proceed to reload that, as if it contained a register. */ 5417117395Skan } 5418117395Skan } 5419117395Skan 5420117395Skan /* If we have a hard register that is ok as an index, 5421117395Skan don't make a reload. If an autoincrement of a nice register 5422117395Skan isn't "valid", it must be that no autoincrement is "valid". 5423117395Skan If that is true and something made an autoincrement anyway, 5424169689Skan this must be a special context where one is allowed. 5425117395Skan (For example, a "push" instruction.) 5426117395Skan We can't improve this address, so leave it alone. */ 5427169689Skan 5428117395Skan /* Otherwise, reload the autoincrement into a suitable hard reg 5429169689Skan and record how much to increment by. */ 5430117395Skan 5431169689Skan if (reg_renumber[regno] >= 0) 5432117395Skan regno = reg_renumber[regno]; 5433117395Skan if ((regno >= FIRST_PSEUDO_REGISTER 5434117395Skan || !(context ? REGNO_OK_FOR_INDEX_P (regno) 5435169689Skan : REGNO_MODE_OK_FOR_BASE_P (regno, mode)))) 5436117395Skan { 5437117395Skan int reloadnum; 5438117395Skan 5439117395Skan /* If we can output the register afterwards, do so, this 5440117395Skan saves the extra update. 5441117395Skan We can do so if we have an INSN - i.e. no JUMP_INSN nor 5442117395Skan CALL_INSN - and it does not set CC0. 5443169689Skan But don't do this if we cannot directly address the 5444169689Skan memory location, since this will make it harder to 5445117395Skan reuse address reloads, and increases register pressure. 5446117395Skan Also don't do this if we can probably update x directly. */ 5447117395Skan rtx equiv = (GET_CODE (XEXP (x, 0)) == MEM 5448117395Skan ? XEXP (x, 0) 5449117395Skan : reg_equiv_mem[regno]); 5450169689Skan int icode = (int) add_optab->handlers[(int) Pmode].insn_code; 5451117395Skan if (insn && GET_CODE (insn) == INSN && equiv 5452117395Skan && memory_operand (equiv, GET_MODE (equiv)) 5453117395Skan#ifdef HAVE_cc0 5454117395Skan && ! sets_cc0_p (PATTERN (insn)) 5455117395Skan#endif 5456169689Skan && ! (icode != CODE_FOR_nothing 5457169689Skan && ((*insn_data[icode].operand[0].predicate) 5458169689Skan (equiv, Pmode)) 5459169689Skan && ((*insn_data[icode].operand[1].predicate) 5460169689Skan (equiv, Pmode)))) 5461169689Skan { 5462117395Skan /* We use the original pseudo for loc, so that 5463117395Skan emit_reload_insns() knows which pseudo this 5464117395Skan reload refers to and updates the pseudo rtx, not 5465169689Skan its equivalent memory location, as well as the 5466169689Skan corresponding entry in reg_last_reload_reg. */ 5467117395Skan loc = &XEXP (x_orig, 0); 5468117395Skan x = XEXP (x, 0); 5469117395Skan reloadnum 5470117395Skan = push_reload (x, x, loc, loc, 5471117395Skan (context ? INDEX_REG_CLASS : 5472117395Skan MODE_BASE_REG_CLASS (mode)), 5473117395Skan GET_MODE (x), GET_MODE (x), 0, 0, 5474117395Skan opnum, RELOAD_OTHER); 5475117395Skan } 5476117395Skan else 5477117395Skan { 5478117395Skan reloadnum 5479169689Skan = push_reload (x, NULL_RTX, loc, (rtx*) 0, 5480117395Skan (context ? INDEX_REG_CLASS : 5481117395Skan MODE_BASE_REG_CLASS (mode)), 5482117395Skan GET_MODE (x), GET_MODE (x), 0, 0, 5483117395Skan opnum, type); 5484117395Skan rld[reloadnum].inc 5485117395Skan = find_inc_amount (PATTERN (this_insn), XEXP (x_orig, 0)); 5486117395Skan 5487117395Skan value = 1; 5488117395Skan } 5489117395Skan 5490169689Skan update_auto_inc_notes (this_insn, REGNO (XEXP (x_orig, 0)), 5491117395Skan reloadnum); 5492169689Skan } 5493169689Skan return value; 5494169689Skan } 5495169689Skan 5496169689Skan else if (GET_CODE (XEXP (x, 0)) == MEM) 5497117395Skan { 5498117395Skan /* This is probably the result of a substitution, by eliminate_regs, 5499117395Skan of an equivalent address for a pseudo that was not allocated to a 5500117395Skan hard register. Verify that the specified address is valid and 5501117395Skan reload it into a register. */ 5502117395Skan /* Variable `tem' might or might not be used in FIND_REG_INC_NOTE. */ 5503169689Skan rtx tem ATTRIBUTE_UNUSED = XEXP (x, 0); 5504117395Skan rtx link; 5505117395Skan int reloadnum; 5506117395Skan 5507117395Skan /* Since we know we are going to reload this item, don't decrement 5508117395Skan for the indirection level. 5509117395Skan 5510117395Skan Note that this is actually conservative: it would be slightly 5511117395Skan more efficient to use the value of SPILL_INDIRECT_LEVELS from 5512117395Skan reload1.c here. */ 5513117395Skan /* We can't use ADDR_TYPE (type) here, because we need to 5514117395Skan write back the value after reading it, hence we actually 5515117395Skan need two registers. */ 5516117395Skan find_reloads_address (GET_MODE (x), &XEXP (x, 0), 5517132718Skan XEXP (XEXP (x, 0), 0), &XEXP (XEXP (x, 0), 0), 5518117395Skan opnum, type, ind_levels, insn); 5519169689Skan 5520117395Skan reloadnum = push_reload (x, NULL_RTX, loc, (rtx*) 0, 5521117395Skan (context ? INDEX_REG_CLASS : 5522117395Skan MODE_BASE_REG_CLASS (mode)), 5523117395Skan GET_MODE (x), VOIDmode, 0, 0, opnum, type); 5524117395Skan rld[reloadnum].inc 5525117395Skan = find_inc_amount (PATTERN (this_insn), XEXP (x, 0)); 5526117395Skan 5527117395Skan link = FIND_REG_INC_NOTE (this_insn, tem); 5528117395Skan if (link != 0) 5529117395Skan push_replacement (&XEXP (link, 0), reloadnum, VOIDmode); 5530117395Skan 5531117395Skan return 1; 5532117395Skan } 5533117395Skan return 0; 5534117395Skan 5535117395Skan case MEM: 5536169689Skan /* This is probably the result of a substitution, by eliminate_regs, of 5537132718Skan an equivalent address for a pseudo that was not allocated to a hard 5538132718Skan register. Verify that the specified address is valid and reload it 5539117395Skan into a register. 5540169689Skan 5541169689Skan Since we know we are going to reload this item, don't decrement for 5542117395Skan the indirection level. 5543117395Skan 5544117395Skan Note that this is actually conservative: it would be slightly more 5545169689Skan efficient to use the value of SPILL_INDIRECT_LEVELS from 5546117395Skan reload1.c here. */ 5547169689Skan 5548117395Skan find_reloads_address (GET_MODE (x), loc, XEXP (x, 0), &XEXP (x, 0), 5549169689Skan opnum, ADDR_TYPE (type), ind_levels, insn); 5550117395Skan push_reload (*loc, NULL_RTX, loc, (rtx*) 0, 5551169689Skan (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)), 5552117395Skan GET_MODE (x), VOIDmode, 0, 0, opnum, type); 5553169689Skan return 1; 5554117395Skan 5555169689Skan case REG: 5556117395Skan { 5557117395Skan int regno = REGNO (x); 5558169689Skan 5559117395Skan if (reg_equiv_constant[regno] != 0) 5560169689Skan { 5561117395Skan find_reloads_address_part (reg_equiv_constant[regno], loc, 5562117395Skan (context ? INDEX_REG_CLASS : 5563169689Skan MODE_BASE_REG_CLASS (mode)), 5564117395Skan GET_MODE (x), opnum, type, ind_levels); 5565117395Skan return 1; 5566169689Skan } 5567117395Skan 5568117395Skan#if 0 /* This might screw code in reload1.c to delete prior output-reload 5569169689Skan that feeds this insn. */ 5570117395Skan if (reg_equiv_mem[regno] != 0) 5571117395Skan { 5572169689Skan push_reload (reg_equiv_mem[regno], NULL_RTX, loc, (rtx*) 0, 5573117395Skan (context ? INDEX_REG_CLASS : 5574117395Skan MODE_BASE_REG_CLASS (mode)), 5575169689Skan GET_MODE (x), VOIDmode, 0, 0, opnum, type); 5576117395Skan return 1; 5577117395Skan } 5578169689Skan#endif 5579169689Skan 5580169689Skan if (reg_equiv_memory_loc[regno] 5581117395Skan && (reg_equiv_address[regno] != 0 || num_not_at_initial_offset)) 5582117395Skan { 5583169689Skan rtx tem = make_memloc (x, regno); 5584117395Skan if (reg_equiv_address[regno] != 0 5585117395Skan || ! rtx_equal_p (tem, reg_equiv_mem[regno])) 5586169689Skan { 5587117395Skan x = tem; 5588117395Skan find_reloads_address (GET_MODE (x), &x, XEXP (x, 0), 5589169689Skan &XEXP (x, 0), opnum, ADDR_TYPE (type), 5590117395Skan ind_levels, insn); 5591169689Skan } 5592169689Skan } 5593169689Skan 5594169689Skan if (reg_renumber[regno] >= 0) 5595117395Skan regno = reg_renumber[regno]; 5596117395Skan 5597117395Skan if ((regno >= FIRST_PSEUDO_REGISTER 5598117395Skan || !(context ? REGNO_OK_FOR_INDEX_P (regno) 5599117395Skan : REGNO_MODE_OK_FOR_BASE_P (regno, mode)))) 5600117395Skan { 5601132718Skan push_reload (x, NULL_RTX, loc, (rtx*) 0, 5602117395Skan (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)), 5603169689Skan GET_MODE (x), VOIDmode, 0, 0, opnum, type); 5604169689Skan return 1; 5605117395Skan } 5606117395Skan 5607117395Skan /* If a register appearing in an address is the subject of a CLOBBER 5608117395Skan in this insn, reload it into some other register to be safe. 5609169689Skan The CLOBBER is supposed to make the register unavailable 5610117395Skan from before this insn to after it. */ 5611117395Skan if (regno_clobbered_p (regno, this_insn, GET_MODE (x), 0)) 5612117395Skan { 5613117395Skan push_reload (x, NULL_RTX, loc, (rtx*) 0, 5614117395Skan (context ? INDEX_REG_CLASS : MODE_BASE_REG_CLASS (mode)), 5615117395Skan GET_MODE (x), VOIDmode, 0, 0, opnum, type); 5616117395Skan return 1; 5617117395Skan } 5618117395Skan } 5619117395Skan return 0; 5620117395Skan 5621117395Skan case SUBREG: 5622117395Skan if (GET_CODE (SUBREG_REG (x)) == REG) 5623117395Skan { 5624169689Skan /* If this is a SUBREG of a hard register and the resulting register 5625169689Skan is of the wrong class, reload the whole SUBREG. This avoids 5626117395Skan needless copies if SUBREG_REG is multi-word. */ 5627169689Skan if (REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER) 5628169689Skan { 5629117395Skan int regno = subreg_regno (x); 5630169689Skan 5631169689Skan if (! (context ? REGNO_OK_FOR_INDEX_P (regno) 5632117395Skan : REGNO_MODE_OK_FOR_BASE_P (regno, mode))) 5633169689Skan { 5634169689Skan push_reload (x, NULL_RTX, loc, (rtx*) 0, 5635117395Skan (context ? INDEX_REG_CLASS : 5636169689Skan MODE_BASE_REG_CLASS (mode)), 5637169689Skan GET_MODE (x), VOIDmode, 0, 0, opnum, type); 5638117395Skan return 1; 5639117395Skan } 5640117395Skan } 5641117395Skan /* If this is a SUBREG of a pseudo-register, and the pseudo-register 5642117395Skan is larger than the class size, then reload the whole SUBREG. */ 5643117395Skan else 5644117395Skan { 5645117395Skan enum reg_class class = (context ? INDEX_REG_CLASS 5646117395Skan : MODE_BASE_REG_CLASS (mode)); 5647117395Skan if (CLASS_MAX_NREGS (class, GET_MODE (SUBREG_REG (x))) 5648117395Skan > reg_class_size[class]) 5649117395Skan { 5650117395Skan x = find_reloads_subreg_address (x, 0, opnum, type, 5651117395Skan ind_levels, insn); 5652117395Skan push_reload (x, NULL_RTX, loc, (rtx*) 0, class, 5653117395Skan GET_MODE (x), VOIDmode, 0, 0, opnum, type); 5654117395Skan return 1; 5655169689Skan } 5656117395Skan } 5657117395Skan } 5658117395Skan break; 5659117395Skan 5660169689Skan default: 5661117395Skan break; 5662117395Skan } 5663117395Skan 5664117395Skan { 5665117395Skan const char *fmt = GET_RTX_FORMAT (code); 5666117395Skan int i; 5667117395Skan 5668117395Skan for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 5669117395Skan { 5670169689Skan if (fmt[i] == 'e') 5671169689Skan find_reloads_address_1 (mode, XEXP (x, i), context, &XEXP (x, i), 5672169689Skan opnum, type, ind_levels, insn); 5673169689Skan } 5674169689Skan } 5675169689Skan 5676169689Skan return 0; 5677169689Skan} 5678169689Skan 5679169689Skan/* X, which is found at *LOC, is a part of an address that needs to be 5680169689Skan reloaded into a register of class CLASS. If X is a constant, or if 5681169689Skan X is a PLUS that contains a constant, check that the constant is a 5682169689Skan legitimate operand and that we are supposed to be able to load 5683169689Skan it into the register. 5684169689Skan 5685169689Skan If not, force the constant into memory and reload the MEM instead. 5686169689Skan 5687169689Skan MODE is the mode to use, in case X is an integer constant. 5688169689Skan 5689169689Skan OPNUM and TYPE describe the purpose of any reloads made. 5690169689Skan 5691169689Skan IND_LEVELS says how many levels of indirect addressing this machine 5692169689Skan supports. */ 5693169689Skan 5694169689Skanstatic void 5695169689Skanfind_reloads_address_part (x, loc, class, mode, opnum, type, ind_levels) 5696169689Skan rtx x; 5697169689Skan rtx *loc; 5698169689Skan enum reg_class class; 5699169689Skan enum machine_mode mode; 5700169689Skan int opnum; 5701169689Skan enum reload_type type; 5702169689Skan int ind_levels; 5703169689Skan{ 5704169689Skan if (CONSTANT_P (x) 5705169689Skan && (! LEGITIMATE_CONSTANT_P (x) 5706169689Skan || PREFERRED_RELOAD_CLASS (x, class) == NO_REGS)) 5707169689Skan { 5708169689Skan rtx tem; 5709169689Skan 5710169689Skan tem = x = force_const_mem (mode, x); 5711169689Skan find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0), 5712169689Skan opnum, type, ind_levels, 0); 5713169689Skan } 5714169689Skan 5715132718Skan else if (GET_CODE (x) == PLUS 5716132718Skan && CONSTANT_P (XEXP (x, 1)) 5717132718Skan && (! LEGITIMATE_CONSTANT_P (XEXP (x, 1)) 5718117395Skan || PREFERRED_RELOAD_CLASS (XEXP (x, 1), class) == NO_REGS)) 5719169689Skan { 5720169689Skan rtx tem; 5721169689Skan 5722169689Skan tem = force_const_mem (GET_MODE (x), XEXP (x, 1)); 5723117395Skan x = gen_rtx_PLUS (GET_MODE (x), XEXP (x, 0), tem); 5724117395Skan find_reloads_address (mode, &tem, XEXP (tem, 0), &XEXP (tem, 0), 5725169689Skan opnum, type, ind_levels, 0); 5726132718Skan } 5727132718Skan 5728117395Skan push_reload (x, NULL_RTX, loc, (rtx*) 0, class, 5729169689Skan mode, VOIDmode, 0, 0, opnum, type); 5730169689Skan} 5731117395Skan 5732117395Skan/* X, a subreg of a pseudo, is a part of an address that needs to be 5733169689Skan reloaded. 5734169689Skan 5735169689Skan If the pseudo is equivalent to a memory location that cannot be directly 5736169689Skan addressed, make the necessary address reloads. 5737169689Skan 5738169689Skan If address reloads have been necessary, or if the address is changed 5739169689Skan by register elimination, return the rtx of the memory location; 5740117395Skan otherwise, return X. 5741169689Skan 5742117395Skan If FORCE_REPLACE is nonzero, unconditionally replace the subreg with the 5743117395Skan memory location. 5744132718Skan 5745132718Skan OPNUM and TYPE identify the purpose of the reload. 5746132718Skan 5747132718Skan IND_LEVELS says how many levels of indirect addressing are 5748132718Skan supported at this point in the address. 5749132718Skan 5750132718Skan INSN, if nonzero, is the insn in which we do the reload. It is used 5751132718Skan to determine where to put USEs for pseudos that we have to replace with 5752132718Skan stack slots. */ 5753169689Skan 5754132718Skanstatic rtx 5755132718Skanfind_reloads_subreg_address (x, force_replace, opnum, type, 5756132718Skan ind_levels, insn) 5757132718Skan rtx x; 5758132718Skan int force_replace; 5759169689Skan int opnum; 5760132718Skan enum reload_type type; 5761132718Skan int ind_levels; 5762169689Skan rtx insn; 5763132718Skan{ 5764169689Skan int regno = REGNO (SUBREG_REG (x)); 5765169689Skan 5766169689Skan if (reg_equiv_memory_loc[regno]) 5767132718Skan { 5768132718Skan /* If the address is not directly addressable, or if the address is not 5769132718Skan offsettable, then it must be replaced. */ 5770132718Skan if (! force_replace 5771132718Skan && (reg_equiv_address[regno] 5772132718Skan || ! offsettable_memref_p (reg_equiv_mem[regno]))) 5773132718Skan force_replace = 1; 5774132718Skan 5775132718Skan if (force_replace || num_not_at_initial_offset) 5776132718Skan { 5777117395Skan rtx tem = make_memloc (SUBREG_REG (x), regno); 5778117395Skan 5779117395Skan /* If the address changes because of register elimination, then 5780117395Skan it must be replaced. */ 5781132718Skan if (force_replace 5782117395Skan || ! rtx_equal_p (tem, reg_equiv_mem[regno])) 5783117395Skan { 5784117395Skan int offset = SUBREG_BYTE (x); 5785117395Skan unsigned outer_size = GET_MODE_SIZE (GET_MODE (x)); 5786169689Skan unsigned inner_size = GET_MODE_SIZE (GET_MODE (SUBREG_REG (x))); 5787169689Skan 5788169689Skan XEXP (tem, 0) = plus_constant (XEXP (tem, 0), offset); 5789169689Skan PUT_MODE (tem, GET_MODE (x)); 5790169689Skan 5791169689Skan /* If this was a paradoxical subreg that we replaced, the 5792169689Skan resulting memory must be sufficiently aligned to allow 5793169689Skan us to widen the mode of the memory. */ 5794169689Skan if (outer_size > inner_size && STRICT_ALIGNMENT) 5795169689Skan { 5796169689Skan rtx base; 5797169689Skan 5798169689Skan base = XEXP (tem, 0); 5799169689Skan if (GET_CODE (base) == PLUS) 5800169689Skan { 5801169689Skan if (GET_CODE (XEXP (base, 1)) == CONST_INT 5802169689Skan && INTVAL (XEXP (base, 1)) % outer_size != 0) 5803169689Skan return x; 5804169689Skan base = XEXP (base, 0); 5805169689Skan } 5806169689Skan if (GET_CODE (base) != REG 5807169689Skan || (REGNO_POINTER_ALIGN (REGNO (base)) 5808169689Skan < outer_size * BITS_PER_UNIT)) 5809169689Skan return x; 5810169689Skan } 5811169689Skan 5812169689Skan find_reloads_address (GET_MODE (tem), &tem, XEXP (tem, 0), 5813169689Skan &XEXP (tem, 0), opnum, ADDR_TYPE (type), 5814169689Skan ind_levels, insn); 5815169689Skan 5816169689Skan /* If this is not a toplevel operand, find_reloads doesn't see 5817169689Skan this substitution. We have to emit a USE of the pseudo so 5818169689Skan that delete_output_reload can see it. */ 5819169689Skan if (replace_reloads && recog_data.operand[opnum] != x) 5820169689Skan /* We mark the USE with QImode so that we recognize it 5821169689Skan as one that can be safely deleted at the end of 5822169689Skan reload. */ 5823169689Skan PUT_MODE (emit_insn_before (gen_rtx_USE (VOIDmode, 5824169689Skan SUBREG_REG (x)), 5825169689Skan insn), QImode); 5826169689Skan x = tem; 5827169689Skan } 5828169689Skan } 5829169689Skan } 5830169689Skan return x; 5831169689Skan} 5832169689Skan 5833169689Skan/* Substitute into the current INSN the registers into which we have reloaded 5834169689Skan the things that need reloading. The array `replacements' 5835169689Skan contains the locations of all pointers that must be changed 5836169689Skan and says what to replace them with. 5837169689Skan 5838169689Skan Return the rtx that X translates into; usually X, but modified. */ 5839117395Skan 5840117395Skanvoid 5841117395Skansubst_reloads (insn) 5842117395Skan rtx insn; 5843132718Skan{ 5844117395Skan int i; 5845132718Skan 5846117395Skan for (i = 0; i < n_replacements; i++) 5847117395Skan { 5848117395Skan struct replacement *r = &replacements[i]; 5849132718Skan rtx reloadreg = rld[r->what].reg_rtx; 5850117395Skan if (reloadreg) 5851117395Skan { 5852117395Skan#ifdef ENABLE_CHECKING 5853117395Skan /* Internal consistency test. Check that we don't modify 5854117395Skan anything in the equivalence arrays. Whenever something from 5855117395Skan those arrays needs to be reloaded, it must be unshared before 5856169689Skan being substituted into; the equivalence must not be modified. 5857169689Skan Otherwise, if the equivalence is used after that, it will 5858169689Skan have been modified, and the thing substituted (probably a 5859169689Skan register) is likely overwritten and not a usable equivalence. */ 5860117395Skan int check_regno; 5861117395Skan 5862117395Skan for (check_regno = 0; check_regno < max_regno; check_regno++) 5863169689Skan { 5864169689Skan#define CHECK_MODF(ARRAY) \ 5865169689Skan if (ARRAY[check_regno] \ 5866169689Skan && loc_mentioned_in_p (r->where, \ 5867117395Skan ARRAY[check_regno])) \ 5868169689Skan abort () 5869117395Skan 5870117395Skan CHECK_MODF (reg_equiv_constant); 5871169689Skan CHECK_MODF (reg_equiv_memory_loc); 5872169689Skan CHECK_MODF (reg_equiv_address); 5873169689Skan CHECK_MODF (reg_equiv_mem); 5874169689Skan#undef CHECK_MODF 5875169689Skan } 5876169689Skan#endif /* ENABLE_CHECKING */ 5877169689Skan 5878117395Skan /* If we're replacing a LABEL_REF with a register, add a 5879117395Skan REG_LABEL note to indicate to flow which label this 5880235623Spfg register refers to. */ 5881235623Spfg if (GET_CODE (*r->where) == LABEL_REF 5882117395Skan && GET_CODE (insn) == JUMP_INSN) 5883235623Spfg REG_NOTES (insn) = gen_rtx_INSN_LIST (REG_LABEL, 5884117395Skan XEXP (*r->where, 0), 5885117395Skan REG_NOTES (insn)); 5886117395Skan 5887117395Skan /* Encapsulate RELOADREG so its machine mode matches what 5888117395Skan used to be there. Note that gen_lowpart_common will 5889117395Skan do the wrong thing if RELOADREG is multi-word. RELOADREG 5890117395Skan will always be a REG here. */ 5891117395Skan if (GET_MODE (reloadreg) != r->mode && r->mode != VOIDmode) 5892117395Skan reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg)); 5893117395Skan 5894117395Skan /* If we are putting this into a SUBREG and RELOADREG is a 5895117395Skan SUBREG, we would be making nested SUBREGs, so we have to fix 5896117395Skan this up. Note that r->where == &SUBREG_REG (*r->subreg_loc). */ 5897117395Skan 5898132718Skan if (r->subreg_loc != 0 && GET_CODE (reloadreg) == SUBREG) 5899132718Skan { 5900132718Skan if (GET_MODE (*r->subreg_loc) 5901132718Skan == GET_MODE (SUBREG_REG (reloadreg))) 5902132718Skan *r->subreg_loc = SUBREG_REG (reloadreg); 5903132718Skan else 5904132718Skan { 5905132718Skan int final_offset = 5906117395Skan SUBREG_BYTE (*r->subreg_loc) + SUBREG_BYTE (reloadreg); 5907169689Skan 5908117395Skan /* When working with SUBREGs the rule is that the byte 5909117395Skan offset must be a multiple of the SUBREG's mode. */ 5910117395Skan final_offset = (final_offset / 5911132718Skan GET_MODE_SIZE (GET_MODE (*r->subreg_loc))); 5912117395Skan final_offset = (final_offset * 5913117395Skan GET_MODE_SIZE (GET_MODE (*r->subreg_loc))); 5914117395Skan 5915117395Skan *r->where = SUBREG_REG (reloadreg); 5916117395Skan SUBREG_BYTE (*r->subreg_loc) = final_offset; 5917117395Skan } 5918132718Skan } 5919169689Skan else 5920169689Skan *r->where = reloadreg; 5921169689Skan } 5922169689Skan /* If reload got no reg and isn't optional, something's wrong. */ 5923169689Skan else if (! rld[r->what].optional) 5924169689Skan abort (); 5925169689Skan } 5926169689Skan} 5927169689Skan 5928169689Skan/* Make a copy of any replacements being done into X and move those 5929169689Skan copies to locations in Y, a copy of X. */ 5930169689Skan 5931169689Skanvoid 5932169689Skancopy_replacements (x, y) 5933169689Skan rtx x, y; 5934169689Skan{ 5935169689Skan /* We can't support X being a SUBREG because we might then need to know its 5936169689Skan location if something inside it was replaced. */ 5937169689Skan if (GET_CODE (x) == SUBREG) 5938132718Skan abort (); 5939132718Skan 5940132718Skan copy_replacements_1 (&x, &y, n_replacements); 5941132718Skan} 5942132718Skan 5943132718Skanstatic void 5944132718Skancopy_replacements_1 (px, py, orig_replacements) 5945132718Skan rtx *px; 5946132718Skan rtx *py; 5947169689Skan int orig_replacements; 5948132718Skan{ 5949132718Skan int i, j; 5950132718Skan rtx x, y; 5951132718Skan struct replacement *r; 5952132718Skan enum rtx_code code; 5953132718Skan const char *fmt; 5954132718Skan 5955132718Skan for (j = 0; j < orig_replacements; j++) 5956132718Skan { 5957132718Skan if (replacements[j].subreg_loc == px) 5958132718Skan { 5959132718Skan r = &replacements[n_replacements++]; 5960132718Skan r->where = replacements[j].where; 5961132718Skan r->subreg_loc = py; 5962132718Skan r->what = replacements[j].what; 5963132718Skan r->mode = replacements[j].mode; 5964132718Skan } 5965132718Skan else if (replacements[j].where == px) 5966169689Skan { 5967169689Skan r = &replacements[n_replacements++]; 5968169689Skan r->where = py; 5969132718Skan r->subreg_loc = 0; 5970132718Skan r->what = replacements[j].what; 5971132718Skan r->mode = replacements[j].mode; 5972132718Skan } 5973132718Skan } 5974132718Skan 5975132718Skan x = *px; 5976169689Skan y = *py; 5977132718Skan code = GET_CODE (x); 5978132718Skan fmt = GET_RTX_FORMAT (code); 5979169689Skan 5980169689Skan for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 5981169689Skan { 5982169689Skan if (fmt[i] == 'e') 5983169689Skan copy_replacements_1 (&XEXP (x, i), &XEXP (y, i), orig_replacements); 5984169689Skan else if (fmt[i] == 'E') 5985169689Skan for (j = XVECLEN (x, i); --j >= 0; ) 5986169689Skan copy_replacements_1 (&XVECEXP (x, i, j), &XVECEXP (y, i, j), 5987169689Skan orig_replacements); 5988169689Skan } 5989169689Skan} 5990169689Skan 5991169689Skan/* Change any replacements being done to *X to be done to *Y */ 5992169689Skan 5993169689Skanvoid 5994169689Skanmove_replacements (x, y) 5995169689Skan rtx *x; 5996169689Skan rtx *y; 5997169689Skan{ 5998169689Skan int i; 5999169689Skan 6000169689Skan for (i = 0; i < n_replacements; i++) 6001169689Skan if (replacements[i].subreg_loc == x) 6002169689Skan replacements[i].subreg_loc = y; 6003169689Skan else if (replacements[i].where == x) 6004169689Skan { 6005169689Skan replacements[i].where = y; 6006169689Skan replacements[i].subreg_loc = 0; 6007169689Skan } 6008169689Skan} 6009169689Skan 6010169689Skan/* If LOC was scheduled to be replaced by something, return the replacement. 6011169689Skan Otherwise, return *LOC. */ 6012169689Skan 6013169689Skanrtx 6014169689Skanfind_replacement (loc) 6015169689Skan rtx *loc; 6016169689Skan{ 6017169689Skan struct replacement *r; 6018169689Skan 6019169689Skan for (r = &replacements[0]; r < &replacements[n_replacements]; r++) 6020169689Skan { 6021169689Skan rtx reloadreg = rld[r->what].reg_rtx; 6022169689Skan 6023169689Skan if (reloadreg && r->where == loc) 6024169689Skan { 6025169689Skan if (r->mode != VOIDmode && GET_MODE (reloadreg) != r->mode) 6026169689Skan reloadreg = gen_rtx_REG (r->mode, REGNO (reloadreg)); 6027169689Skan 6028169689Skan return reloadreg; 6029169689Skan } 6030169689Skan else if (reloadreg && r->subreg_loc == loc) 6031169689Skan { 6032169689Skan /* RELOADREG must be either a REG or a SUBREG. 6033169689Skan 6034169689Skan ??? Is it actually still ever a SUBREG? If so, why? */ 6035169689Skan 6036169689Skan if (GET_CODE (reloadreg) == REG) 6037169689Skan return gen_rtx_REG (GET_MODE (*loc), 6038169689Skan (REGNO (reloadreg) + 6039169689Skan subreg_regno_offset (REGNO (SUBREG_REG (*loc)), 6040169689Skan GET_MODE (SUBREG_REG (*loc)), 6041169689Skan SUBREG_BYTE (*loc), 6042169689Skan GET_MODE (*loc)))); 6043169689Skan else if (GET_MODE (reloadreg) == GET_MODE (*loc)) 6044169689Skan return reloadreg; 6045169689Skan else 6046169689Skan { 6047169689Skan int final_offset = SUBREG_BYTE (reloadreg) + SUBREG_BYTE (*loc); 6048169689Skan 6049169689Skan /* When working with SUBREGs the rule is that the byte 6050169689Skan offset must be a multiple of the SUBREG's mode. */ 6051169689Skan final_offset = (final_offset / GET_MODE_SIZE (GET_MODE (*loc))); 6052169689Skan final_offset = (final_offset * GET_MODE_SIZE (GET_MODE (*loc))); 6053169689Skan return gen_rtx_SUBREG (GET_MODE (*loc), SUBREG_REG (reloadreg), 6054169689Skan final_offset); 6055169689Skan } 6056169689Skan } 6057169689Skan } 6058169689Skan 6059169689Skan /* If *LOC is a PLUS, MINUS, or MULT, see if a replacement is scheduled for 6060169689Skan what's inside and make a new rtl if so. */ 6061169689Skan if (GET_CODE (*loc) == PLUS || GET_CODE (*loc) == MINUS 6062169689Skan || GET_CODE (*loc) == MULT) 6063169689Skan { 6064169689Skan rtx x = find_replacement (&XEXP (*loc, 0)); 6065169689Skan rtx y = find_replacement (&XEXP (*loc, 1)); 6066169689Skan 6067169689Skan if (x != XEXP (*loc, 0) || y != XEXP (*loc, 1)) 6068169689Skan return gen_rtx_fmt_ee (GET_CODE (*loc), GET_MODE (*loc), x, y); 6069169689Skan } 6070169689Skan 6071169689Skan return *loc; 6072169689Skan} 6073169689Skan 6074169689Skan/* Return nonzero if register in range [REGNO, ENDREGNO) 6075169689Skan appears either explicitly or implicitly in X 6076169689Skan other than being stored into (except for earlyclobber operands). 6077169689Skan 6078169689Skan References contained within the substructure at LOC do not count. 6079169689Skan LOC may be zero, meaning don't ignore anything. 6080169689Skan 6081169689Skan This is similar to refers_to_regno_p in rtlanal.c except that we 6082169689Skan look at equivalences for pseudos that didn't get hard registers. */ 6083169689Skan 6084169689Skanint 6085169689Skanrefers_to_regno_for_reload_p (regno, endregno, x, loc) 6086169689Skan unsigned int regno, endregno; 6087169689Skan rtx x; 6088169689Skan rtx *loc; 6089169689Skan{ 6090169689Skan int i; 6091169689Skan unsigned int r; 6092169689Skan RTX_CODE code; 6093169689Skan const char *fmt; 6094169689Skan 6095169689Skan if (x == 0) 6096169689Skan return 0; 6097169689Skan 6098169689Skan repeat: 6099169689Skan code = GET_CODE (x); 6100169689Skan 6101169689Skan switch (code) 6102169689Skan { 6103169689Skan case REG: 6104169689Skan r = REGNO (x); 6105169689Skan 6106169689Skan /* If this is a pseudo, a hard register must not have been allocated. 6107169689Skan X must therefore either be a constant or be in memory. */ 6108169689Skan if (r >= FIRST_PSEUDO_REGISTER) 6109169689Skan { 6110169689Skan if (reg_equiv_memory_loc[r]) 6111169689Skan return refers_to_regno_for_reload_p (regno, endregno, 6112169689Skan reg_equiv_memory_loc[r], 6113169689Skan (rtx*) 0); 6114169689Skan 6115169689Skan if (reg_equiv_constant[r]) 6116169689Skan return 0; 6117169689Skan 6118169689Skan abort (); 6119169689Skan } 6120169689Skan 6121169689Skan return (endregno > r 6122169689Skan && regno < r + (r < FIRST_PSEUDO_REGISTER 6123169689Skan ? HARD_REGNO_NREGS (r, GET_MODE (x)) 6124169689Skan : 1)); 6125169689Skan 6126169689Skan case SUBREG: 6127169689Skan /* If this is a SUBREG of a hard reg, we can see exactly which 6128169689Skan registers are being modified. Otherwise, handle normally. */ 6129169689Skan if (GET_CODE (SUBREG_REG (x)) == REG 6130169689Skan && REGNO (SUBREG_REG (x)) < FIRST_PSEUDO_REGISTER) 6131169689Skan { 6132169689Skan unsigned int inner_regno = subreg_regno (x); 6133169689Skan unsigned int inner_endregno 6134169689Skan = inner_regno + (inner_regno < FIRST_PSEUDO_REGISTER 6135169689Skan ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1); 6136169689Skan 6137169689Skan return endregno > inner_regno && regno < inner_endregno; 6138169689Skan } 6139169689Skan break; 6140169689Skan 6141169689Skan case CLOBBER: 6142169689Skan case SET: 6143169689Skan if (&SET_DEST (x) != loc 6144169689Skan /* Note setting a SUBREG counts as referring to the REG it is in for 6145169689Skan a pseudo but not for hard registers since we can 6146169689Skan treat each word individually. */ 6147169689Skan && ((GET_CODE (SET_DEST (x)) == SUBREG 6148169689Skan && loc != &SUBREG_REG (SET_DEST (x)) 6149169689Skan && GET_CODE (SUBREG_REG (SET_DEST (x))) == REG 6150169689Skan && REGNO (SUBREG_REG (SET_DEST (x))) >= FIRST_PSEUDO_REGISTER 6151169689Skan && refers_to_regno_for_reload_p (regno, endregno, 6152169689Skan SUBREG_REG (SET_DEST (x)), 6153169689Skan loc)) 6154169689Skan /* If the output is an earlyclobber operand, this is 6155169689Skan a conflict. */ 6156169689Skan || ((GET_CODE (SET_DEST (x)) != REG 6157169689Skan || earlyclobber_operand_p (SET_DEST (x))) 6158169689Skan && refers_to_regno_for_reload_p (regno, endregno, 6159169689Skan SET_DEST (x), loc)))) 6160169689Skan return 1; 6161169689Skan 6162169689Skan if (code == CLOBBER || loc == &SET_SRC (x)) 6163169689Skan return 0; 6164169689Skan x = SET_SRC (x); 6165169689Skan goto repeat; 6166169689Skan 6167169689Skan default: 6168169689Skan break; 6169169689Skan } 6170169689Skan 6171169689Skan /* X does not match, so try its subexpressions. */ 6172169689Skan 6173169689Skan fmt = GET_RTX_FORMAT (code); 6174169689Skan for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 6175169689Skan { 6176169689Skan if (fmt[i] == 'e' && loc != &XEXP (x, i)) 6177169689Skan { 6178169689Skan if (i == 0) 6179169689Skan { 6180169689Skan x = XEXP (x, 0); 6181169689Skan goto repeat; 6182169689Skan } 6183169689Skan else 6184169689Skan if (refers_to_regno_for_reload_p (regno, endregno, 6185169689Skan XEXP (x, i), loc)) 6186169689Skan return 1; 6187169689Skan } 6188169689Skan else if (fmt[i] == 'E') 6189169689Skan { 6190169689Skan int j; 6191169689Skan for (j = XVECLEN (x, i) - 1; j >= 0; j--) 6192169689Skan if (loc != &XVECEXP (x, i, j) 6193169689Skan && refers_to_regno_for_reload_p (regno, endregno, 6194169689Skan XVECEXP (x, i, j), loc)) 6195169689Skan return 1; 6196169689Skan } 6197169689Skan } 6198169689Skan return 0; 6199169689Skan} 6200169689Skan 6201169689Skan/* Nonzero if modifying X will affect IN. If X is a register or a SUBREG, 6202169689Skan we check if any register number in X conflicts with the relevant register 6203169689Skan numbers. If X is a constant, return 0. If X is a MEM, return 1 iff IN 6204169689Skan contains a MEM (we don't bother checking for memory addresses that can't 6205169689Skan conflict because we expect this to be a rare case. 6206169689Skan 6207169689Skan This function is similar to reg_overlap_mentioned_p in rtlanal.c except 6208169689Skan that we look at equivalences for pseudos that didn't get hard registers. */ 6209169689Skan 6210169689Skanint 6211169689Skanreg_overlap_mentioned_for_reload_p (x, in) 6212169689Skan rtx x, in; 6213169689Skan{ 6214169689Skan int regno, endregno; 6215169689Skan 6216169689Skan /* Overly conservative. */ 6217169689Skan if (GET_CODE (x) == STRICT_LOW_PART 6218169689Skan || GET_RTX_CLASS (GET_CODE (x)) == 'a') 6219169689Skan x = XEXP (x, 0); 6220169689Skan 6221169689Skan /* If either argument is a constant, then modifying X can not affect IN. */ 6222169689Skan if (CONSTANT_P (x) || CONSTANT_P (in)) 6223169689Skan return 0; 6224169689Skan else if (GET_CODE (x) == SUBREG) 6225169689Skan { 6226169689Skan regno = REGNO (SUBREG_REG (x)); 6227169689Skan if (regno < FIRST_PSEUDO_REGISTER) 6228169689Skan regno += subreg_regno_offset (REGNO (SUBREG_REG (x)), 6229169689Skan GET_MODE (SUBREG_REG (x)), 6230169689Skan SUBREG_BYTE (x), 6231169689Skan GET_MODE (x)); 6232215840Sdim } 6233215840Sdim else if (GET_CODE (x) == REG) 6234215840Sdim { 6235215840Sdim regno = REGNO (x); 6236215840Sdim 6237215840Sdim /* If this is a pseudo, it must not have been assigned a hard register. 6238215840Sdim Therefore, it must either be in memory or be a constant. */ 6239215840Sdim 6240215840Sdim if (regno >= FIRST_PSEUDO_REGISTER) 6241215840Sdim { 6242215840Sdim if (reg_equiv_memory_loc[regno]) 6243215840Sdim return refers_to_mem_for_reload_p (in); 6244215840Sdim else if (reg_equiv_constant[regno]) 6245215840Sdim return 0; 6246215840Sdim abort (); 6247117395Skan } 6248 } 6249 else if (GET_CODE (x) == MEM) 6250 return refers_to_mem_for_reload_p (in); 6251 else if (GET_CODE (x) == SCRATCH || GET_CODE (x) == PC 6252 || GET_CODE (x) == CC0) 6253 return reg_mentioned_p (x, in); 6254 else if (GET_CODE (x) == PLUS) 6255 return (reg_overlap_mentioned_for_reload_p (XEXP (x, 0), in) 6256 || reg_overlap_mentioned_for_reload_p (XEXP (x, 1), in)); 6257 else 6258 abort (); 6259 6260 endregno = regno + (regno < FIRST_PSEUDO_REGISTER 6261 ? HARD_REGNO_NREGS (regno, GET_MODE (x)) : 1); 6262 6263 return refers_to_regno_for_reload_p (regno, endregno, in, (rtx*) 0); 6264} 6265 6266/* Return nonzero if anything in X contains a MEM. Look also for pseudo 6267 registers. */ 6268 6269int 6270refers_to_mem_for_reload_p (x) 6271 rtx x; 6272{ 6273 const char *fmt; 6274 int i; 6275 6276 if (GET_CODE (x) == MEM) 6277 return 1; 6278 6279 if (GET_CODE (x) == REG) 6280 return (REGNO (x) >= FIRST_PSEUDO_REGISTER 6281 && reg_equiv_memory_loc[REGNO (x)]); 6282 6283 fmt = GET_RTX_FORMAT (GET_CODE (x)); 6284 for (i = GET_RTX_LENGTH (GET_CODE (x)) - 1; i >= 0; i--) 6285 if (fmt[i] == 'e' 6286 && (GET_CODE (XEXP (x, i)) == MEM 6287 || refers_to_mem_for_reload_p (XEXP (x, i)))) 6288 return 1; 6289 6290 return 0; 6291} 6292 6293/* Check the insns before INSN to see if there is a suitable register 6294 containing the same value as GOAL. 6295 If OTHER is -1, look for a register in class CLASS. 6296 Otherwise, just see if register number OTHER shares GOAL's value. 6297 6298 Return an rtx for the register found, or zero if none is found. 6299 6300 If RELOAD_REG_P is (short *)1, 6301 we reject any hard reg that appears in reload_reg_rtx 6302 because such a hard reg is also needed coming into this insn. 6303 6304 If RELOAD_REG_P is any other nonzero value, 6305 it is a vector indexed by hard reg number 6306 and we reject any hard reg whose element in the vector is nonnegative 6307 as well as any that appears in reload_reg_rtx. 6308 6309 If GOAL is zero, then GOALREG is a register number; we look 6310 for an equivalent for that register. 6311 6312 MODE is the machine mode of the value we want an equivalence for. 6313 If GOAL is nonzero and not VOIDmode, then it must have mode MODE. 6314 6315 This function is used by jump.c as well as in the reload pass. 6316 6317 If GOAL is the sum of the stack pointer and a constant, we treat it 6318 as if it were a constant except that sp is required to be unchanging. */ 6319 6320rtx 6321find_equiv_reg (goal, insn, class, other, reload_reg_p, goalreg, mode) 6322 rtx goal; 6323 rtx insn; 6324 enum reg_class class; 6325 int other; 6326 short *reload_reg_p; 6327 int goalreg; 6328 enum machine_mode mode; 6329{ 6330 rtx p = insn; 6331 rtx goaltry, valtry, value, where; 6332 rtx pat; 6333 int regno = -1; 6334 int valueno; 6335 int goal_mem = 0; 6336 int goal_const = 0; 6337 int goal_mem_addr_varies = 0; 6338 int need_stable_sp = 0; 6339 int nregs; 6340 int valuenregs; 6341 6342 if (goal == 0) 6343 regno = goalreg; 6344 else if (GET_CODE (goal) == REG) 6345 regno = REGNO (goal); 6346 else if (GET_CODE (goal) == MEM) 6347 { 6348 enum rtx_code code = GET_CODE (XEXP (goal, 0)); 6349 if (MEM_VOLATILE_P (goal)) 6350 return 0; 6351 if (flag_float_store && GET_MODE_CLASS (GET_MODE (goal)) == MODE_FLOAT) 6352 return 0; 6353 /* An address with side effects must be reexecuted. */ 6354 switch (code) 6355 { 6356 case POST_INC: 6357 case PRE_INC: 6358 case POST_DEC: 6359 case PRE_DEC: 6360 case POST_MODIFY: 6361 case PRE_MODIFY: 6362 return 0; 6363 default: 6364 break; 6365 } 6366 goal_mem = 1; 6367 } 6368 else if (CONSTANT_P (goal)) 6369 goal_const = 1; 6370 else if (GET_CODE (goal) == PLUS 6371 && XEXP (goal, 0) == stack_pointer_rtx 6372 && CONSTANT_P (XEXP (goal, 1))) 6373 goal_const = need_stable_sp = 1; 6374 else if (GET_CODE (goal) == PLUS 6375 && XEXP (goal, 0) == frame_pointer_rtx 6376 && CONSTANT_P (XEXP (goal, 1))) 6377 goal_const = 1; 6378 else 6379 return 0; 6380 6381 /* Scan insns back from INSN, looking for one that copies 6382 a value into or out of GOAL. 6383 Stop and give up if we reach a label. */ 6384 6385 while (1) 6386 { 6387 p = PREV_INSN (p); 6388 if (p == 0 || GET_CODE (p) == CODE_LABEL) 6389 return 0; 6390 6391 if (GET_CODE (p) == INSN 6392 /* If we don't want spill regs ... */ 6393 && (! (reload_reg_p != 0 6394 && reload_reg_p != (short *) (HOST_WIDE_INT) 1) 6395 /* ... then ignore insns introduced by reload; they aren't 6396 useful and can cause results in reload_as_needed to be 6397 different from what they were when calculating the need for 6398 spills. If we notice an input-reload insn here, we will 6399 reject it below, but it might hide a usable equivalent. 6400 That makes bad code. It may even abort: perhaps no reg was 6401 spilled for this insn because it was assumed we would find 6402 that equivalent. */ 6403 || INSN_UID (p) < reload_first_uid)) 6404 { 6405 rtx tem; 6406 pat = single_set (p); 6407 6408 /* First check for something that sets some reg equal to GOAL. */ 6409 if (pat != 0 6410 && ((regno >= 0 6411 && true_regnum (SET_SRC (pat)) == regno 6412 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0) 6413 || 6414 (regno >= 0 6415 && true_regnum (SET_DEST (pat)) == regno 6416 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0) 6417 || 6418 (goal_const && rtx_equal_p (SET_SRC (pat), goal) 6419 /* When looking for stack pointer + const, 6420 make sure we don't use a stack adjust. */ 6421 && !reg_overlap_mentioned_for_reload_p (SET_DEST (pat), goal) 6422 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0) 6423 || (goal_mem 6424 && (valueno = true_regnum (valtry = SET_DEST (pat))) >= 0 6425 && rtx_renumbered_equal_p (goal, SET_SRC (pat))) 6426 || (goal_mem 6427 && (valueno = true_regnum (valtry = SET_SRC (pat))) >= 0 6428 && rtx_renumbered_equal_p (goal, SET_DEST (pat))) 6429 /* If we are looking for a constant, 6430 and something equivalent to that constant was copied 6431 into a reg, we can use that reg. */ 6432 || (goal_const && REG_NOTES (p) != 0 6433 && (tem = find_reg_note (p, REG_EQUIV, NULL_RTX)) 6434 && ((rtx_equal_p (XEXP (tem, 0), goal) 6435 && (valueno 6436 = true_regnum (valtry = SET_DEST (pat))) >= 0) 6437 || (GET_CODE (SET_DEST (pat)) == REG 6438 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE 6439 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) 6440 == MODE_FLOAT) 6441 && GET_CODE (goal) == CONST_INT 6442 && 0 != (goaltry 6443 = operand_subword (XEXP (tem, 0), 0, 0, 6444 VOIDmode)) 6445 && rtx_equal_p (goal, goaltry) 6446 && (valtry 6447 = operand_subword (SET_DEST (pat), 0, 0, 6448 VOIDmode)) 6449 && (valueno = true_regnum (valtry)) >= 0))) 6450 || (goal_const && (tem = find_reg_note (p, REG_EQUIV, 6451 NULL_RTX)) 6452 && GET_CODE (SET_DEST (pat)) == REG 6453 && GET_CODE (XEXP (tem, 0)) == CONST_DOUBLE 6454 && (GET_MODE_CLASS (GET_MODE (XEXP (tem, 0))) 6455 == MODE_FLOAT) 6456 && GET_CODE (goal) == CONST_INT 6457 && 0 != (goaltry = operand_subword (XEXP (tem, 0), 1, 0, 6458 VOIDmode)) 6459 && rtx_equal_p (goal, goaltry) 6460 && (valtry 6461 = operand_subword (SET_DEST (pat), 1, 0, VOIDmode)) 6462 && (valueno = true_regnum (valtry)) >= 0))) 6463 { 6464 if (other >= 0) 6465 { 6466 if (valueno != other) 6467 continue; 6468 } 6469 else if ((unsigned) valueno >= FIRST_PSEUDO_REGISTER) 6470 continue; 6471 else 6472 { 6473 int i; 6474 6475 for (i = HARD_REGNO_NREGS (valueno, mode) - 1; i >= 0; i--) 6476 if (! TEST_HARD_REG_BIT (reg_class_contents[(int) class], 6477 valueno + i)) 6478 break; 6479 if (i >= 0) 6480 continue; 6481 } 6482 value = valtry; 6483 where = p; 6484 break; 6485 } 6486 } 6487 } 6488 6489 /* We found a previous insn copying GOAL into a suitable other reg VALUE 6490 (or copying VALUE into GOAL, if GOAL is also a register). 6491 Now verify that VALUE is really valid. */ 6492 6493 /* VALUENO is the register number of VALUE; a hard register. */ 6494 6495 /* Don't try to re-use something that is killed in this insn. We want 6496 to be able to trust REG_UNUSED notes. */ 6497 if (REG_NOTES (where) != 0 && find_reg_note (where, REG_UNUSED, value)) 6498 return 0; 6499 6500 /* If we propose to get the value from the stack pointer or if GOAL is 6501 a MEM based on the stack pointer, we need a stable SP. */ 6502 if (valueno == STACK_POINTER_REGNUM || regno == STACK_POINTER_REGNUM 6503 || (goal_mem && reg_overlap_mentioned_for_reload_p (stack_pointer_rtx, 6504 goal))) 6505 need_stable_sp = 1; 6506 6507 /* Reject VALUE if the copy-insn moved the wrong sort of datum. */ 6508 if (GET_MODE (value) != mode) 6509 return 0; 6510 6511 /* Reject VALUE if it was loaded from GOAL 6512 and is also a register that appears in the address of GOAL. */ 6513 6514 if (goal_mem && value == SET_DEST (single_set (where)) 6515 && refers_to_regno_for_reload_p (valueno, 6516 (valueno 6517 + HARD_REGNO_NREGS (valueno, mode)), 6518 goal, (rtx*) 0)) 6519 return 0; 6520 6521 /* Reject registers that overlap GOAL. */ 6522 6523 if (!goal_mem && !goal_const 6524 && regno + (int) HARD_REGNO_NREGS (regno, mode) > valueno 6525 && regno < valueno + (int) HARD_REGNO_NREGS (valueno, mode)) 6526 return 0; 6527 6528 nregs = HARD_REGNO_NREGS (regno, mode); 6529 valuenregs = HARD_REGNO_NREGS (valueno, mode); 6530 6531 /* Reject VALUE if it is one of the regs reserved for reloads. 6532 Reload1 knows how to reuse them anyway, and it would get 6533 confused if we allocated one without its knowledge. 6534 (Now that insns introduced by reload are ignored above, 6535 this case shouldn't happen, but I'm not positive.) */ 6536 6537 if (reload_reg_p != 0 && reload_reg_p != (short *) (HOST_WIDE_INT) 1) 6538 { 6539 int i; 6540 for (i = 0; i < valuenregs; ++i) 6541 if (reload_reg_p[valueno + i] >= 0) 6542 return 0; 6543 } 6544 6545 /* Reject VALUE if it is a register being used for an input reload 6546 even if it is not one of those reserved. */ 6547 6548 if (reload_reg_p != 0) 6549 { 6550 int i; 6551 for (i = 0; i < n_reloads; i++) 6552 if (rld[i].reg_rtx != 0 && rld[i].in) 6553 { 6554 int regno1 = REGNO (rld[i].reg_rtx); 6555 int nregs1 = HARD_REGNO_NREGS (regno1, 6556 GET_MODE (rld[i].reg_rtx)); 6557 if (regno1 < valueno + valuenregs 6558 && regno1 + nregs1 > valueno) 6559 return 0; 6560 } 6561 } 6562 6563 if (goal_mem) 6564 /* We must treat frame pointer as varying here, 6565 since it can vary--in a nonlocal goto as generated by expand_goto. */ 6566 goal_mem_addr_varies = !CONSTANT_ADDRESS_P (XEXP (goal, 0)); 6567 6568 /* Now verify that the values of GOAL and VALUE remain unaltered 6569 until INSN is reached. */ 6570 6571 p = insn; 6572 while (1) 6573 { 6574 p = PREV_INSN (p); 6575 if (p == where) 6576 return value; 6577 6578 /* Don't trust the conversion past a function call 6579 if either of the two is in a call-clobbered register, or memory. */ 6580 if (GET_CODE (p) == CALL_INSN) 6581 { 6582 int i; 6583 6584 if (goal_mem || need_stable_sp) 6585 return 0; 6586 6587 if (regno >= 0 && regno < FIRST_PSEUDO_REGISTER) 6588 for (i = 0; i < nregs; ++i) 6589 if (call_used_regs[regno + i]) 6590 return 0; 6591 6592 if (valueno >= 0 && valueno < FIRST_PSEUDO_REGISTER) 6593 for (i = 0; i < valuenregs; ++i) 6594 if (call_used_regs[valueno + i]) 6595 return 0; 6596#ifdef NON_SAVING_SETJMP 6597 if (NON_SAVING_SETJMP && find_reg_note (p, REG_SETJMP, NULL)) 6598 return 0; 6599#endif 6600 } 6601 6602 if (INSN_P (p)) 6603 { 6604 pat = PATTERN (p); 6605 6606 /* Watch out for unspec_volatile, and volatile asms. */ 6607 if (volatile_insn_p (pat)) 6608 return 0; 6609 6610 /* If this insn P stores in either GOAL or VALUE, return 0. 6611 If GOAL is a memory ref and this insn writes memory, return 0. 6612 If GOAL is a memory ref and its address is not constant, 6613 and this insn P changes a register used in GOAL, return 0. */ 6614 6615 if (GET_CODE (pat) == COND_EXEC) 6616 pat = COND_EXEC_CODE (pat); 6617 if (GET_CODE (pat) == SET || GET_CODE (pat) == CLOBBER) 6618 { 6619 rtx dest = SET_DEST (pat); 6620 while (GET_CODE (dest) == SUBREG 6621 || GET_CODE (dest) == ZERO_EXTRACT 6622 || GET_CODE (dest) == SIGN_EXTRACT 6623 || GET_CODE (dest) == STRICT_LOW_PART) 6624 dest = XEXP (dest, 0); 6625 if (GET_CODE (dest) == REG) 6626 { 6627 int xregno = REGNO (dest); 6628 int xnregs; 6629 if (REGNO (dest) < FIRST_PSEUDO_REGISTER) 6630 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest)); 6631 else 6632 xnregs = 1; 6633 if (xregno < regno + nregs && xregno + xnregs > regno) 6634 return 0; 6635 if (xregno < valueno + valuenregs 6636 && xregno + xnregs > valueno) 6637 return 0; 6638 if (goal_mem_addr_varies 6639 && reg_overlap_mentioned_for_reload_p (dest, goal)) 6640 return 0; 6641 if (xregno == STACK_POINTER_REGNUM && need_stable_sp) 6642 return 0; 6643 } 6644 else if (goal_mem && GET_CODE (dest) == MEM 6645 && ! push_operand (dest, GET_MODE (dest))) 6646 return 0; 6647 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER 6648 && reg_equiv_memory_loc[regno] != 0) 6649 return 0; 6650 else if (need_stable_sp && push_operand (dest, GET_MODE (dest))) 6651 return 0; 6652 } 6653 else if (GET_CODE (pat) == PARALLEL) 6654 { 6655 int i; 6656 for (i = XVECLEN (pat, 0) - 1; i >= 0; i--) 6657 { 6658 rtx v1 = XVECEXP (pat, 0, i); 6659 if (GET_CODE (v1) == COND_EXEC) 6660 v1 = COND_EXEC_CODE (v1); 6661 if (GET_CODE (v1) == SET || GET_CODE (v1) == CLOBBER) 6662 { 6663 rtx dest = SET_DEST (v1); 6664 while (GET_CODE (dest) == SUBREG 6665 || GET_CODE (dest) == ZERO_EXTRACT 6666 || GET_CODE (dest) == SIGN_EXTRACT 6667 || GET_CODE (dest) == STRICT_LOW_PART) 6668 dest = XEXP (dest, 0); 6669 if (GET_CODE (dest) == REG) 6670 { 6671 int xregno = REGNO (dest); 6672 int xnregs; 6673 if (REGNO (dest) < FIRST_PSEUDO_REGISTER) 6674 xnregs = HARD_REGNO_NREGS (xregno, GET_MODE (dest)); 6675 else 6676 xnregs = 1; 6677 if (xregno < regno + nregs 6678 && xregno + xnregs > regno) 6679 return 0; 6680 if (xregno < valueno + valuenregs 6681 && xregno + xnregs > valueno) 6682 return 0; 6683 if (goal_mem_addr_varies 6684 && reg_overlap_mentioned_for_reload_p (dest, 6685 goal)) 6686 return 0; 6687 if (xregno == STACK_POINTER_REGNUM && need_stable_sp) 6688 return 0; 6689 } 6690 else if (goal_mem && GET_CODE (dest) == MEM 6691 && ! push_operand (dest, GET_MODE (dest))) 6692 return 0; 6693 else if (GET_CODE (dest) == MEM && regno >= FIRST_PSEUDO_REGISTER 6694 && reg_equiv_memory_loc[regno] != 0) 6695 return 0; 6696 else if (need_stable_sp 6697 && push_operand (dest, GET_MODE (dest))) 6698 return 0; 6699 } 6700 } 6701 } 6702 6703 if (GET_CODE (p) == CALL_INSN && CALL_INSN_FUNCTION_USAGE (p)) 6704 { 6705 rtx link; 6706 6707 for (link = CALL_INSN_FUNCTION_USAGE (p); XEXP (link, 1) != 0; 6708 link = XEXP (link, 1)) 6709 { 6710 pat = XEXP (link, 0); 6711 if (GET_CODE (pat) == CLOBBER) 6712 { 6713 rtx dest = SET_DEST (pat); 6714 6715 if (GET_CODE (dest) == REG) 6716 { 6717 int xregno = REGNO (dest); 6718 int xnregs 6719 = HARD_REGNO_NREGS (xregno, GET_MODE (dest)); 6720 6721 if (xregno < regno + nregs 6722 && xregno + xnregs > regno) 6723 return 0; 6724 else if (xregno < valueno + valuenregs 6725 && xregno + xnregs > valueno) 6726 return 0; 6727 else if (goal_mem_addr_varies 6728 && reg_overlap_mentioned_for_reload_p (dest, 6729 goal)) 6730 return 0; 6731 } 6732 6733 else if (goal_mem && GET_CODE (dest) == MEM 6734 && ! push_operand (dest, GET_MODE (dest))) 6735 return 0; 6736 else if (need_stable_sp 6737 && push_operand (dest, GET_MODE (dest))) 6738 return 0; 6739 } 6740 } 6741 } 6742 6743#ifdef AUTO_INC_DEC 6744 /* If this insn auto-increments or auto-decrements 6745 either regno or valueno, return 0 now. 6746 If GOAL is a memory ref and its address is not constant, 6747 and this insn P increments a register used in GOAL, return 0. */ 6748 { 6749 rtx link; 6750 6751 for (link = REG_NOTES (p); link; link = XEXP (link, 1)) 6752 if (REG_NOTE_KIND (link) == REG_INC 6753 && GET_CODE (XEXP (link, 0)) == REG) 6754 { 6755 int incno = REGNO (XEXP (link, 0)); 6756 if (incno < regno + nregs && incno >= regno) 6757 return 0; 6758 if (incno < valueno + valuenregs && incno >= valueno) 6759 return 0; 6760 if (goal_mem_addr_varies 6761 && reg_overlap_mentioned_for_reload_p (XEXP (link, 0), 6762 goal)) 6763 return 0; 6764 } 6765 } 6766#endif 6767 } 6768 } 6769} 6770 6771/* Find a place where INCED appears in an increment or decrement operator 6772 within X, and return the amount INCED is incremented or decremented by. 6773 The value is always positive. */ 6774 6775static int 6776find_inc_amount (x, inced) 6777 rtx x, inced; 6778{ 6779 enum rtx_code code = GET_CODE (x); 6780 const char *fmt; 6781 int i; 6782 6783 if (code == MEM) 6784 { 6785 rtx addr = XEXP (x, 0); 6786 if ((GET_CODE (addr) == PRE_DEC 6787 || GET_CODE (addr) == POST_DEC 6788 || GET_CODE (addr) == PRE_INC 6789 || GET_CODE (addr) == POST_INC) 6790 && XEXP (addr, 0) == inced) 6791 return GET_MODE_SIZE (GET_MODE (x)); 6792 else if ((GET_CODE (addr) == PRE_MODIFY 6793 || GET_CODE (addr) == POST_MODIFY) 6794 && GET_CODE (XEXP (addr, 1)) == PLUS 6795 && XEXP (addr, 0) == XEXP (XEXP (addr, 1), 0) 6796 && XEXP (addr, 0) == inced 6797 && GET_CODE (XEXP (XEXP (addr, 1), 1)) == CONST_INT) 6798 { 6799 i = INTVAL (XEXP (XEXP (addr, 1), 1)); 6800 return i < 0 ? -i : i; 6801 } 6802 } 6803 6804 fmt = GET_RTX_FORMAT (code); 6805 for (i = GET_RTX_LENGTH (code) - 1; i >= 0; i--) 6806 { 6807 if (fmt[i] == 'e') 6808 { 6809 int tem = find_inc_amount (XEXP (x, i), inced); 6810 if (tem != 0) 6811 return tem; 6812 } 6813 if (fmt[i] == 'E') 6814 { 6815 int j; 6816 for (j = XVECLEN (x, i) - 1; j >= 0; j--) 6817 { 6818 int tem = find_inc_amount (XVECEXP (x, i, j), inced); 6819 if (tem != 0) 6820 return tem; 6821 } 6822 } 6823 } 6824 6825 return 0; 6826} 6827 6828/* Return 1 if register REGNO is the subject of a clobber in insn INSN. 6829 If SETS is nonzero, also consider SETs. */ 6830 6831int 6832regno_clobbered_p (regno, insn, mode, sets) 6833 unsigned int regno; 6834 rtx insn; 6835 enum machine_mode mode; 6836 int sets; 6837{ 6838 unsigned int nregs = HARD_REGNO_NREGS (regno, mode); 6839 unsigned int endregno = regno + nregs; 6840 6841 if ((GET_CODE (PATTERN (insn)) == CLOBBER 6842 || (sets && GET_CODE (PATTERN (insn)) == SET)) 6843 && GET_CODE (XEXP (PATTERN (insn), 0)) == REG) 6844 { 6845 unsigned int test = REGNO (XEXP (PATTERN (insn), 0)); 6846 6847 return test >= regno && test < endregno; 6848 } 6849 6850 if (GET_CODE (PATTERN (insn)) == PARALLEL) 6851 { 6852 int i = XVECLEN (PATTERN (insn), 0) - 1; 6853 6854 for (; i >= 0; i--) 6855 { 6856 rtx elt = XVECEXP (PATTERN (insn), 0, i); 6857 if ((GET_CODE (elt) == CLOBBER 6858 || (sets && GET_CODE (PATTERN (insn)) == SET)) 6859 && GET_CODE (XEXP (elt, 0)) == REG) 6860 { 6861 unsigned int test = REGNO (XEXP (elt, 0)); 6862 6863 if (test >= regno && test < endregno) 6864 return 1; 6865 } 6866 } 6867 } 6868 6869 return 0; 6870} 6871 6872static const char *const reload_when_needed_name[] = 6873{ 6874 "RELOAD_FOR_INPUT", 6875 "RELOAD_FOR_OUTPUT", 6876 "RELOAD_FOR_INSN", 6877 "RELOAD_FOR_INPUT_ADDRESS", 6878 "RELOAD_FOR_INPADDR_ADDRESS", 6879 "RELOAD_FOR_OUTPUT_ADDRESS", 6880 "RELOAD_FOR_OUTADDR_ADDRESS", 6881 "RELOAD_FOR_OPERAND_ADDRESS", 6882 "RELOAD_FOR_OPADDR_ADDR", 6883 "RELOAD_OTHER", 6884 "RELOAD_FOR_OTHER_ADDRESS" 6885}; 6886 6887static const char * const reg_class_names[] = REG_CLASS_NAMES; 6888 6889/* These functions are used to print the variables set by 'find_reloads' */ 6890 6891void 6892debug_reload_to_stream (f) 6893 FILE *f; 6894{ 6895 int r; 6896 const char *prefix; 6897 6898 if (! f) 6899 f = stderr; 6900 for (r = 0; r < n_reloads; r++) 6901 { 6902 fprintf (f, "Reload %d: ", r); 6903 6904 if (rld[r].in != 0) 6905 { 6906 fprintf (f, "reload_in (%s) = ", 6907 GET_MODE_NAME (rld[r].inmode)); 6908 print_inline_rtx (f, rld[r].in, 24); 6909 fprintf (f, "\n\t"); 6910 } 6911 6912 if (rld[r].out != 0) 6913 { 6914 fprintf (f, "reload_out (%s) = ", 6915 GET_MODE_NAME (rld[r].outmode)); 6916 print_inline_rtx (f, rld[r].out, 24); 6917 fprintf (f, "\n\t"); 6918 } 6919 6920 fprintf (f, "%s, ", reg_class_names[(int) rld[r].class]); 6921 6922 fprintf (f, "%s (opnum = %d)", 6923 reload_when_needed_name[(int) rld[r].when_needed], 6924 rld[r].opnum); 6925 6926 if (rld[r].optional) 6927 fprintf (f, ", optional"); 6928 6929 if (rld[r].nongroup) 6930 fprintf (f, ", nongroup"); 6931 6932 if (rld[r].inc != 0) 6933 fprintf (f, ", inc by %d", rld[r].inc); 6934 6935 if (rld[r].nocombine) 6936 fprintf (f, ", can't combine"); 6937 6938 if (rld[r].secondary_p) 6939 fprintf (f, ", secondary_reload_p"); 6940 6941 if (rld[r].in_reg != 0) 6942 { 6943 fprintf (f, "\n\treload_in_reg: "); 6944 print_inline_rtx (f, rld[r].in_reg, 24); 6945 } 6946 6947 if (rld[r].out_reg != 0) 6948 { 6949 fprintf (f, "\n\treload_out_reg: "); 6950 print_inline_rtx (f, rld[r].out_reg, 24); 6951 } 6952 6953 if (rld[r].reg_rtx != 0) 6954 { 6955 fprintf (f, "\n\treload_reg_rtx: "); 6956 print_inline_rtx (f, rld[r].reg_rtx, 24); 6957 } 6958 6959 prefix = "\n\t"; 6960 if (rld[r].secondary_in_reload != -1) 6961 { 6962 fprintf (f, "%ssecondary_in_reload = %d", 6963 prefix, rld[r].secondary_in_reload); 6964 prefix = ", "; 6965 } 6966 6967 if (rld[r].secondary_out_reload != -1) 6968 fprintf (f, "%ssecondary_out_reload = %d\n", 6969 prefix, rld[r].secondary_out_reload); 6970 6971 prefix = "\n\t"; 6972 if (rld[r].secondary_in_icode != CODE_FOR_nothing) 6973 { 6974 fprintf (f, "%ssecondary_in_icode = %s", prefix, 6975 insn_data[rld[r].secondary_in_icode].name); 6976 prefix = ", "; 6977 } 6978 6979 if (rld[r].secondary_out_icode != CODE_FOR_nothing) 6980 fprintf (f, "%ssecondary_out_icode = %s", prefix, 6981 insn_data[rld[r].secondary_out_icode].name); 6982 6983 fprintf (f, "\n"); 6984 } 6985} 6986 6987void 6988debug_reload () 6989{ 6990 debug_reload_to_stream (stderr); 6991} 6992