52ede8dd9aea580347574533e28042c0b7adc5eb
[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 PROTO ((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 This information is recorded for the point immediately before the insn
229 (in live_before), and for the point within the insn at which all
230 outputs have just been written to (in live_after). */
231 regset live_before;
232 regset live_after;
233
234 /* Copies of the global variables computed by find_reloads. */
235 struct reload *rld;
236 int n_reloads;
237
238 /* Indicates which registers have already been used for spills. */
239 HARD_REG_SET used_spill_regs;
240
241 /* Describe the needs for reload registers of this insn. */
242 struct needs need;
243
244 /* Nonzero if find_reloads said the insn requires reloading. */
245 unsigned int need_reload:1;
246 /* Nonzero if find_reloads needs to be run during reload_as_needed to
247 perform modifications on any operands. */
248 unsigned int need_operand_change:1;
249 /* Nonzero if eliminate_regs_in_insn said it requires eliminations. */
250 unsigned int need_elim:1;
251 /* Nonzero if this insn was inserted by perform_caller_saves. */
252 unsigned int is_caller_save_insn:1;
253 };
254
255 /* A chain of insn_chain structures to describe all non-note insns in
256 a function. */
257 extern struct insn_chain *reload_insn_chain;
258
259 /* Allocate a new insn_chain structure. */
260 extern struct insn_chain *new_insn_chain PROTO((void));
261
262 extern void compute_use_by_pseudos PROTO((HARD_REG_SET *, regset));
263 #endif
264
265 /* Functions from reload.c: */
266
267 /* Return a memory location that will be used to copy X in mode MODE.
268 If we haven't already made a location for this mode in this insn,
269 call find_reloads_address on the location being returned. */
270 extern rtx get_secondary_mem PROTO((rtx, enum machine_mode,
271 int, enum reload_type));
272
273 /* Clear any secondary memory locations we've made. */
274 extern void clear_secondary_mem PROTO((void));
275
276 /* Transfer all replacements that used to be in reload FROM to be in
277 reload TO. */
278 extern void transfer_replacements PROTO((int, int));
279
280 /* IN_RTX is the value loaded by a reload that we now decided to inherit,
281 or a subpart of it. If we have any replacements registered for IN_RTX,
282 chancel the reloads that were supposed to load them.
283 Return non-zero if we chanceled any reloads. */
284 extern int remove_address_replacements PROTO((rtx in_rtx));
285
286 /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
287 if they are the same hard reg, and has special hacks for
288 autoincrement and autodecrement. */
289 extern int operands_match_p PROTO((rtx, rtx));
290
291 /* Return 1 if altering OP will not modify the value of CLOBBER. */
292 extern int safe_from_earlyclobber PROTO((rtx, rtx));
293
294 /* Search the body of INSN for values that need reloading and record them
295 with push_reload. REPLACE nonzero means record also where the values occur
296 so that subst_reloads can be used. */
297 extern int find_reloads PROTO((rtx, int, int, int, short *));
298
299 /* Compute the sum of X and Y, making canonicalizations assumed in an
300 address, namely: sum constant integers, surround the sum of two
301 constants with a CONST, put the constant as the second operand, and
302 group the constant on the outermost sum. */
303 extern rtx form_sum PROTO((rtx, rtx));
304
305 /* Substitute into the current INSN the registers into which we have reloaded
306 the things that need reloading. */
307 extern void subst_reloads PROTO((void));
308
309 /* Make a copy of any replacements being done into X and move those copies
310 to locations in Y, a copy of X. We only look at the highest level of
311 the RTL. */
312 extern void copy_replacements PROTO((rtx, rtx));
313
314 /* Change any replacements being done to *X to be done to *Y */
315 extern void move_replacements PROTO((rtx *x, rtx *y));
316
317 /* If LOC was scheduled to be replaced by something, return the replacement.
318 Otherwise, return *LOC. */
319 extern rtx find_replacement PROTO((rtx *));
320
321 /* Return nonzero if register in range [REGNO, ENDREGNO)
322 appears either explicitly or implicitly in X
323 other than being stored into. */
324 extern int refers_to_regno_for_reload_p PROTO((int, int, rtx, rtx *));
325
326 /* Nonzero if modifying X will affect IN. */
327 extern int reg_overlap_mentioned_for_reload_p PROTO((rtx, rtx));
328
329 /* Return nonzero if anything in X contains a MEM. Look also for pseudo
330 registers. */
331 extern int refers_to_mem_for_reload_p PROTO((rtx));
332
333 /* Check the insns before INSN to see if there is a suitable register
334 containing the same value as GOAL. */
335 extern rtx find_equiv_reg PROTO((rtx, rtx, enum reg_class, int, short *,
336 int, enum machine_mode));
337
338 /* Return 1 if register REGNO is the subject of a clobber in insn INSN. */
339 extern int regno_clobbered_p PROTO((int, rtx));
340
341 /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
342 int earlyclobber_operand_p PROTO((rtx));
343
344 /* Functions in reload1.c: */
345
346 extern int reloads_conflict PROTO ((int, int));
347
348 int count_occurrences PROTO((rtx, rtx));
349
350 /* Initialize the reload pass once per compilation. */
351 extern void init_reload PROTO((void));
352
353 /* The reload pass itself. */
354 extern int reload PROTO((rtx, int, FILE *));
355
356 /* Mark the slots in regs_ever_live for the hard regs
357 used by pseudo-reg number REGNO. */
358 extern void mark_home_live PROTO((int));
359
360 /* Scan X and replace any eliminable registers (such as fp) with a
361 replacement (such as sp), plus an offset. */
362 extern rtx eliminate_regs PROTO((rtx, enum machine_mode, rtx));
363
364 /* Emit code to perform a reload from IN (which may be a reload register) to
365 OUT (which may also be a reload register). IN or OUT is from operand
366 OPNUM with reload type TYPE. */
367 extern rtx gen_reload PROTO((rtx, rtx, int, enum reload_type));
368
369 /* Deallocate the reload register used by reload number R. */
370 extern void deallocate_reload_reg PROTO((int r));
371
372 /* Functions in caller-save.c: */
373
374 /* Initialize for caller-save. */
375 extern void init_caller_save PROTO((void));
376
377 /* Initialize save areas by showing that we haven't allocated any yet. */
378 extern void init_save_areas PROTO((void));
379
380 /* Allocate save areas for any hard registers that might need saving. */
381 extern void setup_save_areas PROTO((void));
382
383 /* Find the places where hard regs are live across calls and save them. */
384 extern void save_call_clobbered_regs PROTO((void));
385
386 /* Replace (subreg (reg)) with the appropriate (reg) for any operands. */
387 extern void cleanup_subreg_operands PROTO ((rtx));