1 /* Communication between reload.c and reload1.c.
2 Copyright (C) 1987, 91-95, 97-99, 2000 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* If secondary reloads are the same for inputs and outputs, define those
25 #ifdef SECONDARY_RELOAD_CLASS
26 #define SECONDARY_INPUT_RELOAD_CLASS(CLASS, MODE, X) \
27 SECONDARY_RELOAD_CLASS (CLASS, MODE, X)
28 #define SECONDARY_OUTPUT_RELOAD_CLASS(CLASS, MODE, X) \
29 SECONDARY_RELOAD_CLASS (CLASS, MODE, X)
32 /* If either macro is defined, show that we need secondary reloads. */
33 #if defined(SECONDARY_INPUT_RELOAD_CLASS) || defined(SECONDARY_OUTPUT_RELOAD_CLASS)
34 #define HAVE_SECONDARY_RELOADS
37 /* If MEMORY_MOVE_COST isn't defined, give it a default here. */
38 #ifndef MEMORY_MOVE_COST
39 #ifdef HAVE_SECONDARY_RELOADS
40 #define MEMORY_MOVE_COST(MODE,CLASS,IN) \
41 (4 + memory_move_secondary_cost ((MODE), (CLASS), (IN)))
43 #define MEMORY_MOVE_COST(MODE,CLASS,IN) 4
46 extern int memory_move_secondary_cost
PARAMS ((enum machine_mode
, enum reg_class
, int));
48 /* Maximum number of reloads we can need. */
49 #define MAX_RELOADS (2 * MAX_RECOG_OPERANDS * (MAX_REGS_PER_ADDRESS + 1))
51 /* Encode the usage of a reload. The following codes are supported:
53 RELOAD_FOR_INPUT reload of an input operand
54 RELOAD_FOR_OUTPUT likewise, for output
55 RELOAD_FOR_INSN a reload that must not conflict with anything
56 used in the insn, but may conflict with
57 something used before or after the insn
58 RELOAD_FOR_INPUT_ADDRESS reload for parts of the address of an object
59 that is an input reload
60 RELOAD_FOR_INPADDR_ADDRESS reload needed for RELOAD_FOR_INPUT_ADDRESS
61 RELOAD_FOR_OUTPUT_ADDRESS like RELOAD_FOR INPUT_ADDRESS, for output
62 RELOAD_FOR_OUTADDR_ADDRESS reload needed for RELOAD_FOR_OUTPUT_ADDRESS
63 RELOAD_FOR_OPERAND_ADDRESS reload for the address of a non-reloaded
64 operand; these don't conflict with
66 RELOAD_FOR_OPADDR_ADDR reload needed for RELOAD_FOR_OPERAND_ADDRESS
67 reloads; usually secondary reloads
68 RELOAD_OTHER none of the above, usually multiple uses
69 RELOAD_FOR_OTHER_ADDRESS reload for part of the address of an input
70 that is marked RELOAD_OTHER.
72 This used to be "enum reload_when_needed" but some debuggers have trouble
73 with an enum tag and variable of the same name. */
77 RELOAD_FOR_INPUT
, RELOAD_FOR_OUTPUT
, RELOAD_FOR_INSN
,
78 RELOAD_FOR_INPUT_ADDRESS
, RELOAD_FOR_INPADDR_ADDRESS
,
79 RELOAD_FOR_OUTPUT_ADDRESS
, RELOAD_FOR_OUTADDR_ADDRESS
,
80 RELOAD_FOR_OPERAND_ADDRESS
, RELOAD_FOR_OPADDR_ADDR
,
81 RELOAD_OTHER
, RELOAD_FOR_OTHER_ADDRESS
85 /* Each reload is recorded with a structure like this. */
88 /* The value to reload from */
90 /* Where to store reload-reg afterward if nec (often the same as
94 /* The class of registers to reload into. */
97 /* The mode this operand should have when reloaded, on input. */
98 enum machine_mode inmode
;
99 /* The mode this operand should have when reloaded, on output. */
100 enum machine_mode outmode
;
102 /* The mode of the reload register. */
103 enum machine_mode mode
;
105 /* the largest number of registers this reload will require. */
108 /* Positive amount to increment or decrement by if
109 reload_in is a PRE_DEC, PRE_INC, POST_DEC, POST_INC.
110 Ignored otherwise (don't assume it is zero). */
112 /* A reg for which reload_in is the equivalent.
113 If reload_in is a symbol_ref which came from
114 reg_equiv_constant, then this is the pseudo
115 which has that symbol_ref as equivalent. */
119 /* Used in find_reload_regs to record the allocated register. */
121 /* This is the register to reload into. If it is zero when `find_reloads'
122 returns, you must find a suitable register in the class specified by
123 reload_reg_class, and store here an rtx for that register with mode from
124 reload_inmode or reload_outmode. */
126 /* The operand number being reloaded. This is used to group related reloads
127 and need not always be equal to the actual operand number in the insn,
128 though it current will be; for in-out operands, it is one of the two
132 /* Gives the reload number of a secondary input reload, when needed;
134 int secondary_in_reload
;
135 /* Gives the reload number of a secondary output reload, when needed;
137 int secondary_out_reload
;
138 /* If a secondary input reload is required, gives the INSN_CODE that uses the
139 secondary reload as a scratch register, or CODE_FOR_nothing if the
140 secondary reload register is to be an intermediate register. */
141 enum insn_code secondary_in_icode
;
142 /* Likewise, for a secondary output reload. */
143 enum insn_code secondary_out_icode
;
145 /* Classifies reload as needed either for addressing an input reload,
146 addressing an output, for addressing a non-reloaded mem ref, or for
147 unspecified purposes (i.e., more than one of the above). */
148 enum reload_type when_needed
;
150 /* Nonzero for an optional reload. Optional reloads are ignored unless the
151 value is already sitting in a register. */
152 unsigned int optional
:1;
153 /* nonzero if this reload shouldn't be combined with another reload. */
154 unsigned int nocombine
:1;
155 /* Nonzero if this is a secondary register for one or more reloads. */
156 unsigned int secondary_p
:1;
157 /* Nonzero if this reload must use a register not already allocated to a
159 unsigned int nongroup
:1;
162 extern struct reload rld
[MAX_RELOADS
];
163 extern int n_reloads
;
166 extern rtx
*reg_equiv_constant
;
167 extern rtx
*reg_equiv_memory_loc
;
168 extern rtx
*reg_equiv_address
;
169 extern rtx
*reg_equiv_mem
;
171 /* All the "earlyclobber" operands of the current insn
172 are recorded here. */
173 extern int n_earlyclobbers
;
174 extern rtx reload_earlyclobbers
[MAX_RECOG_OPERANDS
];
176 /* Save the number of operands. */
177 extern int reload_n_operands
;
179 /* First uid used by insns created by reload in this function.
180 Used in find_equiv_reg. */
181 extern int reload_first_uid
;
183 /* Nonzero if indirect addressing is supported when the innermost MEM is
184 of the form (MEM (SYMBOL_REF sym)). It is assumed that the level to
185 which these are valid is the same as spill_indirect_levels, above. */
187 extern char indirect_symref_ok
;
189 /* Nonzero if an address (plus (reg frame_pointer) (reg ...)) is valid. */
190 extern char double_reg_address_ok
;
192 extern int num_not_at_initial_offset
;
195 /* These arrays record the insn_code of insns that may be needed to
196 perform input and output reloads of special objects. They provide a
197 place to pass a scratch register. */
198 extern enum insn_code reload_in_optab
[];
199 extern enum insn_code reload_out_optab
[];
204 /* [0] is normal, [1] is nongroup. */
205 short regs
[2][N_REG_CLASSES
];
206 short groups
[N_REG_CLASSES
];
209 #if defined SET_HARD_REG_BIT && defined CLEAR_REG_SET
210 /* This structure describes instructions which are relevant for reload.
211 Apart from all regular insns, this also includes CODE_LABELs, since they
212 must be examined for register elimination. */
215 /* Links to the neighbour instructions. */
216 struct insn_chain
*next
, *prev
;
218 /* Link through a chains set up by calculate_needs_all_insns, containing
219 all insns that need reloading. */
220 struct insn_chain
*next_need_reload
;
222 /* The basic block this insn is in. */
224 /* The rtx of the insn. */
226 /* Register life information: record all live hard registers, and all
227 live pseudos that have a hard register. */
228 regset_head live_throughout
;
229 regset_head dead_or_set
;
231 /* Copies of the global variables computed by find_reloads. */
235 /* Indicates which registers have already been used for spills. */
236 HARD_REG_SET used_spill_regs
;
238 /* Describe the needs for reload registers of this insn. */
241 /* Nonzero if find_reloads said the insn requires reloading. */
242 unsigned int need_reload
:1;
243 /* Nonzero if find_reloads needs to be run during reload_as_needed to
244 perform modifications on any operands. */
245 unsigned int need_operand_change
:1;
246 /* Nonzero if eliminate_regs_in_insn said it requires eliminations. */
247 unsigned int need_elim
:1;
248 /* Nonzero if this insn was inserted by perform_caller_saves. */
249 unsigned int is_caller_save_insn
:1;
252 /* A chain of insn_chain structures to describe all non-note insns in
254 extern struct insn_chain
*reload_insn_chain
;
256 /* Allocate a new insn_chain structure. */
257 extern struct insn_chain
*new_insn_chain
PARAMS ((void));
259 extern void compute_use_by_pseudos
PARAMS ((HARD_REG_SET
*, regset
));
262 /* Functions from reload.c: */
264 /* Return a memory location that will be used to copy X in mode MODE.
265 If we haven't already made a location for this mode in this insn,
266 call find_reloads_address on the location being returned. */
267 extern rtx get_secondary_mem
PARAMS ((rtx
, enum machine_mode
,
268 int, enum reload_type
));
270 /* Clear any secondary memory locations we've made. */
271 extern void clear_secondary_mem
PARAMS ((void));
273 /* Transfer all replacements that used to be in reload FROM to be in
275 extern void transfer_replacements
PARAMS ((int, int));
277 /* IN_RTX is the value loaded by a reload that we now decided to inherit,
278 or a subpart of it. If we have any replacements registered for IN_RTX,
279 chancel the reloads that were supposed to load them.
280 Return non-zero if we chanceled any reloads. */
281 extern int remove_address_replacements
PARAMS ((rtx in_rtx
));
283 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
284 if they are the same hard reg, and has special hacks for
285 autoincrement and autodecrement. */
286 extern int operands_match_p
PARAMS ((rtx
, rtx
));
288 /* Return 1 if altering OP will not modify the value of CLOBBER. */
289 extern int safe_from_earlyclobber
PARAMS ((rtx
, rtx
));
291 /* Search the body of INSN for values that need reloading and record them
292 with push_reload. REPLACE nonzero means record also where the values occur
293 so that subst_reloads can be used. */
294 extern int find_reloads
PARAMS ((rtx
, int, int, int, short *));
296 /* Compute the sum of X and Y, making canonicalizations assumed in an
297 address, namely: sum constant integers, surround the sum of two
298 constants with a CONST, put the constant as the second operand, and
299 group the constant on the outermost sum. */
300 extern rtx form_sum
PARAMS ((rtx
, rtx
));
302 /* Substitute into the current INSN the registers into which we have reloaded
303 the things that need reloading. */
304 extern void subst_reloads
PARAMS ((void));
306 /* Make a copy of any replacements being done into X and move those copies
307 to locations in Y, a copy of X. We only look at the highest level of
309 extern void copy_replacements
PARAMS ((rtx
, rtx
));
311 /* Change any replacements being done to *X to be done to *Y */
312 extern void move_replacements
PARAMS ((rtx
*x
, rtx
*y
));
314 /* If LOC was scheduled to be replaced by something, return the replacement.
315 Otherwise, return *LOC. */
316 extern rtx find_replacement
PARAMS ((rtx
*));
318 /* Return nonzero if register in range [REGNO, ENDREGNO)
319 appears either explicitly or implicitly in X
320 other than being stored into. */
321 extern int refers_to_regno_for_reload_p
PARAMS ((int, int, rtx
, rtx
*));
323 /* Nonzero if modifying X will affect IN. */
324 extern int reg_overlap_mentioned_for_reload_p
PARAMS ((rtx
, rtx
));
326 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
328 extern int refers_to_mem_for_reload_p
PARAMS ((rtx
));
330 /* Check the insns before INSN to see if there is a suitable register
331 containing the same value as GOAL. */
332 extern rtx find_equiv_reg
PARAMS ((rtx
, rtx
, enum reg_class
, int, short *,
333 int, enum machine_mode
));
335 /* Return 1 if register REGNO is the subject of a clobber in insn INSN. */
336 extern int regno_clobbered_p
PARAMS ((int, rtx
));
338 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
339 int earlyclobber_operand_p
PARAMS ((rtx
));
341 /* Functions in reload1.c: */
343 extern int reloads_conflict
PARAMS ((int, int));
345 int count_occurrences
PARAMS ((rtx
, rtx
));
347 /* Initialize the reload pass once per compilation. */
348 extern void init_reload
PARAMS ((void));
350 /* The reload pass itself. */
351 extern int reload
PARAMS ((rtx
, int, FILE *));
353 /* Mark the slots in regs_ever_live for the hard regs
354 used by pseudo-reg number REGNO. */
355 extern void mark_home_live
PARAMS ((int));
357 /* Scan X and replace any eliminable registers (such as fp) with a
358 replacement (such as sp), plus an offset. */
359 extern rtx eliminate_regs
PARAMS ((rtx
, enum machine_mode
, rtx
));
361 /* Emit code to perform a reload from IN (which may be a reload register) to
362 OUT (which may also be a reload register). IN or OUT is from operand
363 OPNUM with reload type TYPE. */
364 extern rtx gen_reload
PARAMS ((rtx
, rtx
, int, enum reload_type
));
366 /* Deallocate the reload register used by reload number R. */
367 extern void deallocate_reload_reg
PARAMS ((int r
));
369 /* Functions in caller-save.c: */
371 /* Initialize for caller-save. */
372 extern void init_caller_save
PARAMS ((void));
374 /* Initialize save areas by showing that we haven't allocated any yet. */
375 extern void init_save_areas
PARAMS ((void));
377 /* Allocate save areas for any hard registers that might need saving. */
378 extern void setup_save_areas
PARAMS ((void));
380 /* Find the places where hard regs are live across calls and save them. */
381 extern void save_call_clobbered_regs
PARAMS ((void));
383 /* Replace (subreg (reg)) with the appropriate (reg) for any operands. */
384 extern void cleanup_subreg_operands
PARAMS ((rtx
));