dcf51190abed285999e3e61663e125f9442203a9
[gcc.git] / gcc / reload.h
1 /* Communication between reload.c and reload1.c.
2 Copyright (C) 1987, 91-95, 97, 1998 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
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)
9 any later version.
10
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.
15
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. */
20
21
22 /* If secondary reloads are the same for inputs and outputs, define those
23 macros here. */
24
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)
30 #endif
31
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
35 #endif
36
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)))
42 #else
43 #define MEMORY_MOVE_COST(MODE,CLASS,IN) 4
44 #endif
45 #endif
46 extern int memory_move_secondary_cost PARAMS ((enum machine_mode, enum reg_class, int));
47
48 /* Maximum number of reloads we can need. */
49 #define MAX_RELOADS (2 * MAX_RECOG_OPERANDS * (MAX_REGS_PER_ADDRESS + 1))
50
51 /* Encode the usage of a reload. The following codes are supported:
52
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
65 any other addresses.
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.
71
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. */
74
75 enum reload_type
76 {
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
82 };
83
84 #ifdef MAX_INSN_CODE
85 /* Each reload is recorded with a structure like this. */
86 struct reload
87 {
88 /* The value to reload from */
89 rtx in;
90 /* Where to store reload-reg afterward if nec (often the same as
91 reload_in) */
92 rtx out;
93
94 /* The class of registers to reload into. */
95 enum reg_class class;
96
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;
101
102 /* The mode of the reload register. */
103 enum machine_mode mode;
104
105 /* the largest number of registers this reload will require. */
106 int nregs;
107
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). */
111 int inc;
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. */
116 rtx in_reg;
117 rtx out_reg;
118
119 /* Used in find_reload_regs to record the allocated register. */
120 int regno;
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. */
125 rtx reg_rtx;
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
129 operand numbers. */
130 int opnum;
131
132 /* Gives the reload number of a secondary input reload, when needed;
133 otherwise -1. */
134 int secondary_in_reload;
135 /* Gives the reload number of a secondary output reload, when needed;
136 otherwise -1. */
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;
144
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;
149
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
158 group. */
159 unsigned int nongroup:1;
160 };
161
162 extern struct reload rld[MAX_RELOADS];
163 extern int n_reloads;
164 #endif
165
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;
170
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];
175
176 /* Save the number of operands. */
177 extern int reload_n_operands;
178
179 /* First uid used by insns created by reload in this function.
180 Used in find_equiv_reg. */
181 extern int reload_first_uid;
182
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. */
186
187 extern char indirect_symref_ok;
188
189 /* Nonzero if an address (plus (reg frame_pointer) (reg ...)) is valid. */
190 extern char double_reg_address_ok;
191
192 extern int num_not_at_initial_offset;
193
194 #ifdef MAX_INSN_CODE
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[];
200 #endif
201
202 struct needs
203 {
204 /* [0] is normal, [1] is nongroup. */
205 short regs[2][N_REG_CLASSES];
206 short groups[N_REG_CLASSES];
207 };
208
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. */
213 struct insn_chain
214 {
215 /* Links to the neighbour instructions. */
216 struct insn_chain *next, *prev;
217
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;
221
222 /* The basic block this insn is in. */
223 int block;
224 /* The rtx of the insn. */
225 rtx 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;
230
231 /* Copies of the global variables computed by find_reloads. */
232 struct reload *rld;
233 int n_reloads;
234
235 /* Indicates which registers have already been used for spills. */
236 HARD_REG_SET used_spill_regs;
237
238 /* Describe the needs for reload registers of this insn. */
239 struct needs need;
240
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;
250 };
251
252 /* A chain of insn_chain structures to describe all non-note insns in
253 a function. */
254 extern struct insn_chain *reload_insn_chain;
255
256 /* Allocate a new insn_chain structure. */
257 extern struct insn_chain *new_insn_chain PARAMS ((void));
258
259 extern void compute_use_by_pseudos PARAMS ((HARD_REG_SET *, regset));
260 #endif
261
262 /* Functions from reload.c: */
263
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));
269
270 /* Clear any secondary memory locations we've made. */
271 extern void clear_secondary_mem PARAMS ((void));
272
273 /* Transfer all replacements that used to be in reload FROM to be in
274 reload TO. */
275 extern void transfer_replacements PARAMS ((int, int));
276
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));
282
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));
287
288 /* Return 1 if altering OP will not modify the value of CLOBBER. */
289 extern int safe_from_earlyclobber PARAMS ((rtx, rtx));
290
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 *));
295
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));
301
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));
305
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
308 the RTL. */
309 extern void copy_replacements PARAMS ((rtx, rtx));
310
311 /* Change any replacements being done to *X to be done to *Y */
312 extern void move_replacements PARAMS ((rtx *x, rtx *y));
313
314 /* If LOC was scheduled to be replaced by something, return the replacement.
315 Otherwise, return *LOC. */
316 extern rtx find_replacement PARAMS ((rtx *));
317
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 *));
322
323 /* Nonzero if modifying X will affect IN. */
324 extern int reg_overlap_mentioned_for_reload_p PARAMS ((rtx, rtx));
325
326 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
327 registers. */
328 extern int refers_to_mem_for_reload_p PARAMS ((rtx));
329
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));
334
335 /* Return 1 if register REGNO is the subject of a clobber in insn INSN. */
336 extern int regno_clobbered_p PARAMS ((int, rtx));
337
338 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
339 int earlyclobber_operand_p PARAMS ((rtx));
340
341 /* Functions in reload1.c: */
342
343 extern int reloads_conflict PARAMS ((int, int));
344
345 int count_occurrences PARAMS ((rtx, rtx));
346
347 /* Initialize the reload pass once per compilation. */
348 extern void init_reload PARAMS ((void));
349
350 /* The reload pass itself. */
351 extern int reload PARAMS ((rtx, int, FILE *));
352
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));
356
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));
360
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));
365
366 /* Deallocate the reload register used by reload number R. */
367 extern void deallocate_reload_reg PARAMS ((int r));
368
369 /* Functions in caller-save.c: */
370
371 /* Initialize for caller-save. */
372 extern void init_caller_save PARAMS ((void));
373
374 /* Initialize save areas by showing that we haven't allocated any yet. */
375 extern void init_save_areas PARAMS ((void));
376
377 /* Allocate save areas for any hard registers that might need saving. */
378 extern void setup_save_areas PARAMS ((void));
379
380 /* Find the places where hard regs are live across calls and save them. */
381 extern void save_call_clobbered_regs PARAMS ((void));
382
383 /* Replace (subreg (reg)) with the appropriate (reg) for any operands. */
384 extern void cleanup_subreg_operands PARAMS ((rtx));