00001 /* Communication between reload.c and reload1.c. 00002 Copyright (C) 1987, 1991, 1992, 1993, 1994, 1995, 1997, 1998, 00003 1999, 2000, 2001 Free Software Foundation, Inc. 00004 00005 This file is part of GCC. 00006 00007 GCC is free software; you can redistribute it and/or modify it under 00008 the terms of the GNU General Public License as published by the Free 00009 Software Foundation; either version 2, or (at your option) any later 00010 version. 00011 00012 GCC is distributed in the hope that it will be useful, but WITHOUT ANY 00013 WARRANTY; without even the implied warranty of MERCHANTABILITY or 00014 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 00015 for more details. 00016 00017 You should have received a copy of the GNU General Public License 00018 along with GCC; see the file COPYING. If not, write to the Free 00019 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 00020 02111-1307, USA. */ 00021 00022 00023 /* If secondary reloads are the same for inputs and outputs, define those 00024 macros here. */ 00025 00026 #ifdef SECONDARY_RELOAD_CLASS 00027 #define SECONDARY_INPUT_RELOAD_CLASS(CLASS, MODE, X) \ 00028 SECONDARY_RELOAD_CLASS (CLASS, MODE, X) 00029 #define SECONDARY_OUTPUT_RELOAD_CLASS(CLASS, MODE, X) \ 00030 SECONDARY_RELOAD_CLASS (CLASS, MODE, X) 00031 #endif 00032 00033 /* If either macro is defined, show that we need secondary reloads. */ 00034 #if defined(SECONDARY_INPUT_RELOAD_CLASS) || defined(SECONDARY_OUTPUT_RELOAD_CLASS) 00035 #define HAVE_SECONDARY_RELOADS 00036 #endif 00037 00038 /* If MEMORY_MOVE_COST isn't defined, give it a default here. */ 00039 #ifndef MEMORY_MOVE_COST 00040 #ifdef HAVE_SECONDARY_RELOADS 00041 #define MEMORY_MOVE_COST(MODE,CLASS,IN) \ 00042 (4 + memory_move_secondary_cost ((MODE), (CLASS), (IN))) 00043 #else 00044 #define MEMORY_MOVE_COST(MODE,CLASS,IN) 4 00045 #endif 00046 #endif 00047 extern int memory_move_secondary_cost PARAMS ((enum machine_mode, enum reg_class, int)); 00048 00049 /* Maximum number of reloads we can need. */ 00050 #define MAX_RELOADS (2 * MAX_RECOG_OPERANDS * (MAX_REGS_PER_ADDRESS + 1)) 00051 00052 /* Encode the usage of a reload. The following codes are supported: 00053 00054 RELOAD_FOR_INPUT reload of an input operand 00055 RELOAD_FOR_OUTPUT likewise, for output 00056 RELOAD_FOR_INSN a reload that must not conflict with anything 00057 used in the insn, but may conflict with 00058 something used before or after the insn 00059 RELOAD_FOR_INPUT_ADDRESS reload for parts of the address of an object 00060 that is an input reload 00061 RELOAD_FOR_INPADDR_ADDRESS reload needed for RELOAD_FOR_INPUT_ADDRESS 00062 RELOAD_FOR_OUTPUT_ADDRESS like RELOAD_FOR INPUT_ADDRESS, for output 00063 RELOAD_FOR_OUTADDR_ADDRESS reload needed for RELOAD_FOR_OUTPUT_ADDRESS 00064 RELOAD_FOR_OPERAND_ADDRESS reload for the address of a non-reloaded 00065 operand; these don't conflict with 00066 any other addresses. 00067 RELOAD_FOR_OPADDR_ADDR reload needed for RELOAD_FOR_OPERAND_ADDRESS 00068 reloads; usually secondary reloads 00069 RELOAD_OTHER none of the above, usually multiple uses 00070 RELOAD_FOR_OTHER_ADDRESS reload for part of the address of an input 00071 that is marked RELOAD_OTHER. 00072 00073 This used to be "enum reload_when_needed" but some debuggers have trouble 00074 with an enum tag and variable of the same name. */ 00075 00076 enum reload_type 00077 { 00078 RELOAD_FOR_INPUT, RELOAD_FOR_OUTPUT, RELOAD_FOR_INSN, 00079 RELOAD_FOR_INPUT_ADDRESS, RELOAD_FOR_INPADDR_ADDRESS, 00080 RELOAD_FOR_OUTPUT_ADDRESS, RELOAD_FOR_OUTADDR_ADDRESS, 00081 RELOAD_FOR_OPERAND_ADDRESS, RELOAD_FOR_OPADDR_ADDR, 00082 RELOAD_OTHER, RELOAD_FOR_OTHER_ADDRESS 00083 }; 00084 00085 #ifdef GCC_INSN_CODES_H 00086 /* Each reload is recorded with a structure like this. */ 00087 struct reload 00088 { 00089 /* The value to reload from */ 00090 rtx in; 00091 /* Where to store reload-reg afterward if nec (often the same as 00092 reload_in) */ 00093 rtx out; 00094 00095 /* The class of registers to reload into. */ 00096 enum reg_class class; 00097 00098 /* The mode this operand should have when reloaded, on input. */ 00099 enum machine_mode inmode; 00100 /* The mode this operand should have when reloaded, on output. */ 00101 enum machine_mode outmode; 00102 00103 /* The mode of the reload register. */ 00104 enum machine_mode mode; 00105 00106 /* the largest number of registers this reload will require. */ 00107 unsigned int nregs; 00108 00109 /* Positive amount to increment or decrement by if 00110 reload_in is a PRE_DEC, PRE_INC, POST_DEC, POST_INC. 00111 Ignored otherwise (don't assume it is zero). */ 00112 int inc; 00113 /* A reg for which reload_in is the equivalent. 00114 If reload_in is a symbol_ref which came from 00115 reg_equiv_constant, then this is the pseudo 00116 which has that symbol_ref as equivalent. */ 00117 rtx in_reg; 00118 rtx out_reg; 00119 00120 /* Used in find_reload_regs to record the allocated register. */ 00121 int regno; 00122 /* This is the register to reload into. If it is zero when `find_reloads' 00123 returns, you must find a suitable register in the class specified by 00124 reload_reg_class, and store here an rtx for that register with mode from 00125 reload_inmode or reload_outmode. */ 00126 rtx reg_rtx; 00127 /* The operand number being reloaded. This is used to group related reloads 00128 and need not always be equal to the actual operand number in the insn, 00129 though it current will be; for in-out operands, it is one of the two 00130 operand numbers. */ 00131 int opnum; 00132 00133 /* Gives the reload number of a secondary input reload, when needed; 00134 otherwise -1. */ 00135 int secondary_in_reload; 00136 /* Gives the reload number of a secondary output reload, when needed; 00137 otherwise -1. */ 00138 int secondary_out_reload; 00139 /* If a secondary input reload is required, gives the INSN_CODE that uses the 00140 secondary reload as a scratch register, or CODE_FOR_nothing if the 00141 secondary reload register is to be an intermediate register. */ 00142 enum insn_code secondary_in_icode; 00143 /* Likewise, for a secondary output reload. */ 00144 enum insn_code secondary_out_icode; 00145 00146 /* Classifies reload as needed either for addressing an input reload, 00147 addressing an output, for addressing a non-reloaded mem ref, or for 00148 unspecified purposes (i.e., more than one of the above). */ 00149 enum reload_type when_needed; 00150 00151 /* Nonzero for an optional reload. Optional reloads are ignored unless the 00152 value is already sitting in a register. */ 00153 unsigned int optional:1; 00154 /* nonzero if this reload shouldn't be combined with another reload. */ 00155 unsigned int nocombine:1; 00156 /* Nonzero if this is a secondary register for one or more reloads. */ 00157 unsigned int secondary_p:1; 00158 /* Nonzero if this reload must use a register not already allocated to a 00159 group. */ 00160 unsigned int nongroup:1; 00161 }; 00162 00163 extern struct reload rld[MAX_RELOADS]; 00164 extern int n_reloads; 00165 #endif 00166 00167 extern rtx *reg_equiv_constant; 00168 extern rtx *reg_equiv_memory_loc; 00169 extern rtx *reg_equiv_address; 00170 extern rtx *reg_equiv_mem; 00171 00172 /* All the "earlyclobber" operands of the current insn 00173 are recorded here. */ 00174 extern int n_earlyclobbers; 00175 extern rtx reload_earlyclobbers[MAX_RECOG_OPERANDS]; 00176 00177 /* Save the number of operands. */ 00178 extern int reload_n_operands; 00179 00180 /* First uid used by insns created by reload in this function. 00181 Used in find_equiv_reg. */ 00182 extern int reload_first_uid; 00183 00184 /* Nonzero if indirect addressing is supported when the innermost MEM is 00185 of the form (MEM (SYMBOL_REF sym)). It is assumed that the level to 00186 which these are valid is the same as spill_indirect_levels, above. */ 00187 00188 extern char indirect_symref_ok; 00189 00190 /* Nonzero if an address (plus (reg frame_pointer) (reg ...)) is valid. */ 00191 extern char double_reg_address_ok; 00192 00193 extern int num_not_at_initial_offset; 00194 00195 struct needs 00196 { 00197 /* [0] is normal, [1] is nongroup. */ 00198 short regs[2][N_REG_CLASSES]; 00199 short groups[N_REG_CLASSES]; 00200 }; 00201 00202 #if defined SET_HARD_REG_BIT && defined CLEAR_REG_SET 00203 /* This structure describes instructions which are relevant for reload. 00204 Apart from all regular insns, this also includes CODE_LABELs, since they 00205 must be examined for register elimination. */ 00206 struct insn_chain 00207 { 00208 /* Links to the neighbor instructions. */ 00209 struct insn_chain *next, *prev; 00210 00211 /* Link through a chains set up by calculate_needs_all_insns, containing 00212 all insns that need reloading. */ 00213 struct insn_chain *next_need_reload; 00214 00215 /* The basic block this insn is in. */ 00216 int block; 00217 /* The rtx of the insn. */ 00218 rtx insn; 00219 /* Register life information: record all live hard registers, and all 00220 live pseudos that have a hard register. */ 00221 regset_head live_throughout; 00222 regset_head dead_or_set; 00223 00224 /* Copies of the global variables computed by find_reloads. */ 00225 struct reload *rld; 00226 int n_reloads; 00227 00228 /* Indicates which registers have already been used for spills. */ 00229 HARD_REG_SET used_spill_regs; 00230 00231 /* Describe the needs for reload registers of this insn. */ 00232 struct needs need; 00233 00234 /* Nonzero if find_reloads said the insn requires reloading. */ 00235 unsigned int need_reload:1; 00236 /* Nonzero if find_reloads needs to be run during reload_as_needed to 00237 perform modifications on any operands. */ 00238 unsigned int need_operand_change:1; 00239 /* Nonzero if eliminate_regs_in_insn said it requires eliminations. */ 00240 unsigned int need_elim:1; 00241 /* Nonzero if this insn was inserted by perform_caller_saves. */ 00242 unsigned int is_caller_save_insn:1; 00243 }; 00244 00245 /* A chain of insn_chain structures to describe all non-note insns in 00246 a function. */ 00247 extern struct insn_chain *reload_insn_chain; 00248 00249 /* Allocate a new insn_chain structure. */ 00250 extern struct insn_chain *new_insn_chain PARAMS ((void)); 00251 00252 extern void compute_use_by_pseudos PARAMS ((HARD_REG_SET *, regset)); 00253 #endif 00254 00255 /* Functions from reload.c: */ 00256 00257 /* Return a memory location that will be used to copy X in mode MODE. 00258 If we haven't already made a location for this mode in this insn, 00259 call find_reloads_address on the location being returned. */ 00260 extern rtx get_secondary_mem PARAMS ((rtx, enum machine_mode, 00261 int, enum reload_type)); 00262 00263 /* Clear any secondary memory locations we've made. */ 00264 extern void clear_secondary_mem PARAMS ((void)); 00265 00266 /* Transfer all replacements that used to be in reload FROM to be in 00267 reload TO. */ 00268 extern void transfer_replacements PARAMS ((int, int)); 00269 00270 /* IN_RTX is the value loaded by a reload that we now decided to inherit, 00271 or a subpart of it. If we have any replacements registered for IN_RTX, 00272 chancel the reloads that were supposed to load them. 00273 Return nonzero if we chanceled any reloads. */ 00274 extern int remove_address_replacements PARAMS ((rtx in_rtx)); 00275 00276 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match 00277 if they are the same hard reg, and has special hacks for 00278 autoincrement and autodecrement. */ 00279 extern int operands_match_p PARAMS ((rtx, rtx)); 00280 00281 /* Return 1 if altering OP will not modify the value of CLOBBER. */ 00282 extern int safe_from_earlyclobber PARAMS ((rtx, rtx)); 00283 00284 /* Search the body of INSN for values that need reloading and record them 00285 with push_reload. REPLACE nonzero means record also where the values occur 00286 so that subst_reloads can be used. */ 00287 extern int find_reloads PARAMS ((rtx, int, int, int, short *)); 00288 00289 /* Compute the sum of X and Y, making canonicalizations assumed in an 00290 address, namely: sum constant integers, surround the sum of two 00291 constants with a CONST, put the constant as the second operand, and 00292 group the constant on the outermost sum. */ 00293 extern rtx form_sum PARAMS ((rtx, rtx)); 00294 00295 /* Substitute into the current INSN the registers into which we have reloaded 00296 the things that need reloading. */ 00297 extern void subst_reloads PARAMS ((rtx)); 00298 00299 /* Make a copy of any replacements being done into X and move those copies 00300 to locations in Y, a copy of X. We only look at the highest level of 00301 the RTL. */ 00302 extern void copy_replacements PARAMS ((rtx, rtx)); 00303 00304 /* Change any replacements being done to *X to be done to *Y */ 00305 extern void move_replacements PARAMS ((rtx *x, rtx *y)); 00306 00307 /* If LOC was scheduled to be replaced by something, return the replacement. 00308 Otherwise, return *LOC. */ 00309 extern rtx find_replacement PARAMS ((rtx *)); 00310 00311 /* Return nonzero if register in range [REGNO, ENDREGNO) 00312 appears either explicitly or implicitly in X 00313 other than being stored into. */ 00314 extern int refers_to_regno_for_reload_p PARAMS ((unsigned int, unsigned int, 00315 rtx, rtx *)); 00316 00317 /* Nonzero if modifying X will affect IN. */ 00318 extern int reg_overlap_mentioned_for_reload_p PARAMS ((rtx, rtx)); 00319 00320 /* Return nonzero if anything in X contains a MEM. Look also for pseudo 00321 registers. */ 00322 extern int refers_to_mem_for_reload_p PARAMS ((rtx)); 00323 00324 /* Check the insns before INSN to see if there is a suitable register 00325 containing the same value as GOAL. */ 00326 extern rtx find_equiv_reg PARAMS ((rtx, rtx, enum reg_class, int, short *, 00327 int, enum machine_mode)); 00328 00329 /* Return 1 if register REGNO is the subject of a clobber in insn INSN. */ 00330 extern int regno_clobbered_p PARAMS ((unsigned int, rtx, enum machine_mode, 00331 int)); 00332 00333 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */ 00334 extern int earlyclobber_operand_p PARAMS ((rtx)); 00335 00336 /* Record one reload that needs to be performed. */ 00337 extern int push_reload PARAMS ((rtx, rtx, rtx *, rtx *, enum reg_class, 00338 enum machine_mode, enum machine_mode, 00339 int, int, int, enum reload_type)); 00340 00341 /* Functions in reload1.c: */ 00342 00343 extern void reload_cse_regs PARAMS ((rtx)); 00344 extern int reloads_conflict PARAMS ((int, int)); 00345 00346 /* Initialize the reload pass once per compilation. */ 00347 extern void init_reload PARAMS ((void)); 00348 00349 /* The reload pass itself. */ 00350 extern int reload PARAMS ((rtx, int)); 00351 00352 /* Mark the slots in regs_ever_live for the hard regs 00353 used by pseudo-reg number REGNO. */ 00354 extern void mark_home_live PARAMS ((int)); 00355 00356 /* Scan X and replace any eliminable registers (such as fp) with a 00357 replacement (such as sp), plus an offset. */ 00358 extern rtx eliminate_regs PARAMS ((rtx, enum machine_mode, rtx)); 00359 00360 /* Emit code to perform a reload from IN (which may be a reload register) to 00361 OUT (which may also be a reload register). IN or OUT is from operand 00362 OPNUM with reload type TYPE. */ 00363 extern rtx gen_reload PARAMS ((rtx, rtx, int, enum reload_type)); 00364 00365 /* Deallocate the reload register used by reload number R. */ 00366 extern void deallocate_reload_reg PARAMS ((int r)); 00367 00368 /* Functions in caller-save.c: */ 00369 00370 /* Initialize for caller-save. */ 00371 extern void init_caller_save PARAMS ((void)); 00372 00373 /* Initialize save areas by showing that we haven't allocated any yet. */ 00374 extern void init_save_areas PARAMS ((void)); 00375 00376 /* Allocate save areas for any hard registers that might need saving. */ 00377 extern void setup_save_areas PARAMS ((void)); 00378 00379 /* Find the places where hard regs are live across calls and save them. */ 00380 extern void save_call_clobbered_regs PARAMS ((void)); 00381 00382 /* Replace (subreg (reg)) with the appropriate (reg) for any operands. */ 00383 extern void cleanup_subreg_operands PARAMS ((rtx)); 00384 00385 /* Debugging support. */ 00386 extern void debug_reload_to_stream PARAMS ((FILE *)); 00387 extern void debug_reload PARAMS ((void));
1.5.6