OSDN Git Service

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