reload.h revision 1.1 1 1.1 mrg /* Communication between reload.c, reload1.c and the rest of compiler.
2 1.1 mrg Copyright (C) 1987, 1991, 1992, 1993, 1994, 1995, 1997, 1998, 1999,
3 1.1 mrg 2000, 2001, 2003, 2004, 2007, 2008, 2010
4 1.1 mrg Free Software Foundation, Inc.
5 1.1 mrg
6 1.1 mrg This file is part of GCC.
7 1.1 mrg
8 1.1 mrg GCC is free software; you can redistribute it and/or modify it under
9 1.1 mrg the terms of the GNU General Public License as published by the Free
10 1.1 mrg Software Foundation; either version 3, or (at your option) any later
11 1.1 mrg version.
12 1.1 mrg
13 1.1 mrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 1.1 mrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 1.1 mrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 1.1 mrg for more details.
17 1.1 mrg
18 1.1 mrg You should have received a copy of the GNU General Public License
19 1.1 mrg along with GCC; see the file COPYING3. If not see
20 1.1 mrg <http://www.gnu.org/licenses/>. */
21 1.1 mrg
22 1.1 mrg
23 1.1 mrg /* If secondary reloads are the same for inputs and outputs, define those
24 1.1 mrg macros here. */
25 1.1 mrg
26 1.1 mrg #ifdef SECONDARY_RELOAD_CLASS
27 1.1 mrg #define SECONDARY_INPUT_RELOAD_CLASS(CLASS, MODE, X) \
28 1.1 mrg SECONDARY_RELOAD_CLASS (CLASS, MODE, X)
29 1.1 mrg #define SECONDARY_OUTPUT_RELOAD_CLASS(CLASS, MODE, X) \
30 1.1 mrg SECONDARY_RELOAD_CLASS (CLASS, MODE, X)
31 1.1 mrg #endif
32 1.1 mrg
33 1.1 mrg /* If MEMORY_MOVE_COST isn't defined, give it a default here. */
34 1.1 mrg #ifndef MEMORY_MOVE_COST
35 1.1 mrg #define MEMORY_MOVE_COST(MODE,CLASS,IN) \
36 1.1 mrg (4 + memory_move_secondary_cost ((MODE), (CLASS), (IN)))
37 1.1 mrg #endif
38 1.1 mrg extern int memory_move_secondary_cost (enum machine_mode, enum reg_class, int);
39 1.1 mrg
40 1.1 mrg /* Maximum number of reloads we can need. */
41 1.1 mrg #define MAX_RELOADS (2 * MAX_RECOG_OPERANDS * (MAX_REGS_PER_ADDRESS + 1))
42 1.1 mrg
43 1.1 mrg /* Encode the usage of a reload. The following codes are supported:
44 1.1 mrg
45 1.1 mrg RELOAD_FOR_INPUT reload of an input operand
46 1.1 mrg RELOAD_FOR_OUTPUT likewise, for output
47 1.1 mrg RELOAD_FOR_INSN a reload that must not conflict with anything
48 1.1 mrg used in the insn, but may conflict with
49 1.1 mrg something used before or after the insn
50 1.1 mrg RELOAD_FOR_INPUT_ADDRESS reload for parts of the address of an object
51 1.1 mrg that is an input reload
52 1.1 mrg RELOAD_FOR_INPADDR_ADDRESS reload needed for RELOAD_FOR_INPUT_ADDRESS
53 1.1 mrg RELOAD_FOR_OUTPUT_ADDRESS like RELOAD_FOR INPUT_ADDRESS, for output
54 1.1 mrg RELOAD_FOR_OUTADDR_ADDRESS reload needed for RELOAD_FOR_OUTPUT_ADDRESS
55 1.1 mrg RELOAD_FOR_OPERAND_ADDRESS reload for the address of a non-reloaded
56 1.1 mrg operand; these don't conflict with
57 1.1 mrg any other addresses.
58 1.1 mrg RELOAD_FOR_OPADDR_ADDR reload needed for RELOAD_FOR_OPERAND_ADDRESS
59 1.1 mrg reloads; usually secondary reloads
60 1.1 mrg RELOAD_OTHER none of the above, usually multiple uses
61 1.1 mrg RELOAD_FOR_OTHER_ADDRESS reload for part of the address of an input
62 1.1 mrg that is marked RELOAD_OTHER.
63 1.1 mrg
64 1.1 mrg This used to be "enum reload_when_needed" but some debuggers have trouble
65 1.1 mrg with an enum tag and variable of the same name. */
66 1.1 mrg
67 1.1 mrg enum reload_type
68 1.1 mrg {
69 1.1 mrg RELOAD_FOR_INPUT, RELOAD_FOR_OUTPUT, RELOAD_FOR_INSN,
70 1.1 mrg RELOAD_FOR_INPUT_ADDRESS, RELOAD_FOR_INPADDR_ADDRESS,
71 1.1 mrg RELOAD_FOR_OUTPUT_ADDRESS, RELOAD_FOR_OUTADDR_ADDRESS,
72 1.1 mrg RELOAD_FOR_OPERAND_ADDRESS, RELOAD_FOR_OPADDR_ADDR,
73 1.1 mrg RELOAD_OTHER, RELOAD_FOR_OTHER_ADDRESS
74 1.1 mrg };
75 1.1 mrg
76 1.1 mrg #ifdef GCC_INSN_CODES_H
77 1.1 mrg /* Each reload is recorded with a structure like this. */
78 1.1 mrg struct reload
79 1.1 mrg {
80 1.1 mrg /* The value to reload from */
81 1.1 mrg rtx in;
82 1.1 mrg /* Where to store reload-reg afterward if nec (often the same as
83 1.1 mrg reload_in) */
84 1.1 mrg rtx out;
85 1.1 mrg
86 1.1 mrg /* The class of registers to reload into. */
87 1.1 mrg enum reg_class rclass;
88 1.1 mrg
89 1.1 mrg /* The mode this operand should have when reloaded, on input. */
90 1.1 mrg enum machine_mode inmode;
91 1.1 mrg /* The mode this operand should have when reloaded, on output. */
92 1.1 mrg enum machine_mode outmode;
93 1.1 mrg
94 1.1 mrg /* The mode of the reload register. */
95 1.1 mrg enum machine_mode mode;
96 1.1 mrg
97 1.1 mrg /* the largest number of registers this reload will require. */
98 1.1 mrg unsigned int nregs;
99 1.1 mrg
100 1.1 mrg /* Positive amount to increment or decrement by if
101 1.1 mrg reload_in is a PRE_DEC, PRE_INC, POST_DEC, POST_INC.
102 1.1 mrg Ignored otherwise (don't assume it is zero). */
103 1.1 mrg int inc;
104 1.1 mrg /* A reg for which reload_in is the equivalent.
105 1.1 mrg If reload_in is a symbol_ref which came from
106 1.1 mrg reg_equiv_constant, then this is the pseudo
107 1.1 mrg which has that symbol_ref as equivalent. */
108 1.1 mrg rtx in_reg;
109 1.1 mrg rtx out_reg;
110 1.1 mrg
111 1.1 mrg /* Used in find_reload_regs to record the allocated register. */
112 1.1 mrg int regno;
113 1.1 mrg /* This is the register to reload into. If it is zero when `find_reloads'
114 1.1 mrg returns, you must find a suitable register in the class specified by
115 1.1 mrg reload_reg_class, and store here an rtx for that register with mode from
116 1.1 mrg reload_inmode or reload_outmode. */
117 1.1 mrg rtx reg_rtx;
118 1.1 mrg /* The operand number being reloaded. This is used to group related reloads
119 1.1 mrg and need not always be equal to the actual operand number in the insn,
120 1.1 mrg though it current will be; for in-out operands, it is one of the two
121 1.1 mrg operand numbers. */
122 1.1 mrg int opnum;
123 1.1 mrg
124 1.1 mrg /* Gives the reload number of a secondary input reload, when needed;
125 1.1 mrg otherwise -1. */
126 1.1 mrg int secondary_in_reload;
127 1.1 mrg /* Gives the reload number of a secondary output reload, when needed;
128 1.1 mrg otherwise -1. */
129 1.1 mrg int secondary_out_reload;
130 1.1 mrg /* If a secondary input reload is required, gives the INSN_CODE that uses the
131 1.1 mrg secondary reload as a scratch register, or CODE_FOR_nothing if the
132 1.1 mrg secondary reload register is to be an intermediate register. */
133 1.1 mrg enum insn_code secondary_in_icode;
134 1.1 mrg /* Likewise, for a secondary output reload. */
135 1.1 mrg enum insn_code secondary_out_icode;
136 1.1 mrg
137 1.1 mrg /* Classifies reload as needed either for addressing an input reload,
138 1.1 mrg addressing an output, for addressing a non-reloaded mem ref, or for
139 1.1 mrg unspecified purposes (i.e., more than one of the above). */
140 1.1 mrg enum reload_type when_needed;
141 1.1 mrg
142 1.1 mrg /* Nonzero for an optional reload. Optional reloads are ignored unless the
143 1.1 mrg value is already sitting in a register. */
144 1.1 mrg unsigned int optional:1;
145 1.1 mrg /* nonzero if this reload shouldn't be combined with another reload. */
146 1.1 mrg unsigned int nocombine:1;
147 1.1 mrg /* Nonzero if this is a secondary register for one or more reloads. */
148 1.1 mrg unsigned int secondary_p:1;
149 1.1 mrg /* Nonzero if this reload must use a register not already allocated to a
150 1.1 mrg group. */
151 1.1 mrg unsigned int nongroup:1;
152 1.1 mrg };
153 1.1 mrg
154 1.1 mrg extern struct reload rld[MAX_RELOADS];
155 1.1 mrg extern int n_reloads;
156 1.1 mrg #endif
157 1.1 mrg
158 1.1 mrg extern GTY (()) VEC(rtx,gc) *reg_equiv_memory_loc_vec;
159 1.1 mrg extern rtx *reg_equiv_constant;
160 1.1 mrg extern rtx *reg_equiv_invariant;
161 1.1 mrg extern rtx *reg_equiv_memory_loc;
162 1.1 mrg extern rtx *reg_equiv_address;
163 1.1 mrg extern rtx *reg_equiv_mem;
164 1.1 mrg extern rtx *reg_equiv_alt_mem_list;
165 1.1 mrg
166 1.1 mrg /* Element N is the list of insns that initialized reg N from its equivalent
167 1.1 mrg constant or memory slot. */
168 1.1 mrg extern GTY((length("reg_equiv_init_size"))) rtx *reg_equiv_init;
169 1.1 mrg
170 1.1 mrg /* The size of the previous array, for GC purposes. */
171 1.1 mrg extern GTY(()) int reg_equiv_init_size;
172 1.1 mrg
173 1.1 mrg /* All the "earlyclobber" operands of the current insn
174 1.1 mrg are recorded here. */
175 1.1 mrg extern int n_earlyclobbers;
176 1.1 mrg extern rtx reload_earlyclobbers[MAX_RECOG_OPERANDS];
177 1.1 mrg
178 1.1 mrg /* Save the number of operands. */
179 1.1 mrg extern int reload_n_operands;
180 1.1 mrg
181 1.1 mrg /* First uid used by insns created by reload in this function.
182 1.1 mrg Used in find_equiv_reg. */
183 1.1 mrg extern int reload_first_uid;
184 1.1 mrg
185 1.1 mrg /* Nonzero if indirect addressing is supported when the innermost MEM is
186 1.1 mrg of the form (MEM (SYMBOL_REF sym)). It is assumed that the level to
187 1.1 mrg which these are valid is the same as spill_indirect_levels, above. */
188 1.1 mrg
189 1.1 mrg extern char indirect_symref_ok;
190 1.1 mrg
191 1.1 mrg /* Nonzero if an address (plus (reg frame_pointer) (reg ...)) is valid. */
192 1.1 mrg extern char double_reg_address_ok;
193 1.1 mrg
194 1.1 mrg extern int num_not_at_initial_offset;
195 1.1 mrg
196 1.1 mrg #if defined SET_HARD_REG_BIT && defined CLEAR_REG_SET
197 1.1 mrg /* This structure describes instructions which are relevant for reload.
198 1.1 mrg Apart from all regular insns, this also includes CODE_LABELs, since they
199 1.1 mrg must be examined for register elimination. */
200 1.1 mrg struct insn_chain
201 1.1 mrg {
202 1.1 mrg /* Links to the neighbor instructions. */
203 1.1 mrg struct insn_chain *next, *prev;
204 1.1 mrg
205 1.1 mrg /* Link through a chains set up by calculate_needs_all_insns, containing
206 1.1 mrg all insns that need reloading. */
207 1.1 mrg struct insn_chain *next_need_reload;
208 1.1 mrg
209 1.1 mrg /* The rtx of the insn. */
210 1.1 mrg rtx insn;
211 1.1 mrg
212 1.1 mrg /* The basic block this insn is in. */
213 1.1 mrg int block;
214 1.1 mrg
215 1.1 mrg /* Nonzero if find_reloads said the insn requires reloading. */
216 1.1 mrg unsigned int need_reload:1;
217 1.1 mrg /* Nonzero if find_reloads needs to be run during reload_as_needed to
218 1.1 mrg perform modifications on any operands. */
219 1.1 mrg unsigned int need_operand_change:1;
220 1.1 mrg /* Nonzero if eliminate_regs_in_insn said it requires eliminations. */
221 1.1 mrg unsigned int need_elim:1;
222 1.1 mrg /* Nonzero if this insn was inserted by perform_caller_saves. */
223 1.1 mrg unsigned int is_caller_save_insn:1;
224 1.1 mrg
225 1.1 mrg /* Register life information: record all live hard registers, and
226 1.1 mrg all live pseudos that have a hard register. This set also
227 1.1 mrg contains pseudos spilled by IRA. */
228 1.1 mrg regset_head live_throughout;
229 1.1 mrg regset_head dead_or_set;
230 1.1 mrg
231 1.1 mrg /* Copies of the global variables computed by find_reloads. */
232 1.1 mrg struct reload *rld;
233 1.1 mrg int n_reloads;
234 1.1 mrg
235 1.1 mrg /* Indicates which registers have already been used for spills. */
236 1.1 mrg HARD_REG_SET used_spill_regs;
237 1.1 mrg };
238 1.1 mrg
239 1.1 mrg /* A chain of insn_chain structures to describe all non-note insns in
240 1.1 mrg a function. */
241 1.1 mrg extern struct insn_chain *reload_insn_chain;
242 1.1 mrg
243 1.1 mrg /* Allocate a new insn_chain structure. */
244 1.1 mrg extern struct insn_chain *new_insn_chain (void);
245 1.1 mrg
246 1.1 mrg extern void compute_use_by_pseudos (HARD_REG_SET *, regset);
247 1.1 mrg #endif
248 1.1 mrg
249 1.1 mrg /* Functions from reload.c: */
250 1.1 mrg
251 1.1 mrg extern enum reg_class secondary_reload_class (bool, enum reg_class,
252 1.1 mrg enum machine_mode, rtx);
253 1.1 mrg
254 1.1 mrg #ifdef GCC_INSN_CODES_H
255 1.1 mrg extern enum reg_class scratch_reload_class (enum insn_code);
256 1.1 mrg #endif
257 1.1 mrg
258 1.1 mrg /* Return a memory location that will be used to copy X in mode MODE.
259 1.1 mrg If we haven't already made a location for this mode in this insn,
260 1.1 mrg call find_reloads_address on the location being returned. */
261 1.1 mrg extern rtx get_secondary_mem (rtx, enum machine_mode, int, enum reload_type);
262 1.1 mrg
263 1.1 mrg /* Clear any secondary memory locations we've made. */
264 1.1 mrg extern void clear_secondary_mem (void);
265 1.1 mrg
266 1.1 mrg /* Transfer all replacements that used to be in reload FROM to be in
267 1.1 mrg reload TO. */
268 1.1 mrg extern void transfer_replacements (int, int);
269 1.1 mrg
270 1.1 mrg /* IN_RTX is the value loaded by a reload that we now decided to inherit,
271 1.1 mrg or a subpart of it. If we have any replacements registered for IN_RTX,
272 1.1 mrg cancel the reloads that were supposed to load them.
273 1.1 mrg Return nonzero if we canceled any reloads. */
274 1.1 mrg extern int remove_address_replacements (rtx in_rtx);
275 1.1 mrg
276 1.1 mrg /* Like rtx_equal_p except that it allows a REG and a SUBREG to match
277 1.1 mrg if they are the same hard reg, and has special hacks for
278 1.1 mrg autoincrement and autodecrement. */
279 1.1 mrg extern int operands_match_p (rtx, rtx);
280 1.1 mrg
281 1.1 mrg /* Return 1 if altering OP will not modify the value of CLOBBER. */
282 1.1 mrg extern int safe_from_earlyclobber (rtx, rtx);
283 1.1 mrg
284 1.1 mrg /* Search the body of INSN for values that need reloading and record them
285 1.1 mrg with push_reload. REPLACE nonzero means record also where the values occur
286 1.1 mrg so that subst_reloads can be used. */
287 1.1 mrg extern int find_reloads (rtx, int, int, int, short *);
288 1.1 mrg
289 1.1 mrg /* Compute the sum of X and Y, making canonicalizations assumed in an
290 1.1 mrg address, namely: sum constant integers, surround the sum of two
291 1.1 mrg constants with a CONST, put the constant as the second operand, and
292 1.1 mrg group the constant on the outermost sum. */
293 1.1 mrg extern rtx form_sum (enum machine_mode, rtx, rtx);
294 1.1 mrg
295 1.1 mrg /* Substitute into the current INSN the registers into which we have reloaded
296 1.1 mrg the things that need reloading. */
297 1.1 mrg extern void subst_reloads (rtx);
298 1.1 mrg
299 1.1 mrg /* Make a copy of any replacements being done into X and move those copies
300 1.1 mrg to locations in Y, a copy of X. We only look at the highest level of
301 1.1 mrg the RTL. */
302 1.1 mrg extern void copy_replacements (rtx, rtx);
303 1.1 mrg
304 1.1 mrg /* Change any replacements being done to *X to be done to *Y */
305 1.1 mrg extern void move_replacements (rtx *x, rtx *y);
306 1.1 mrg
307 1.1 mrg /* If LOC was scheduled to be replaced by something, return the replacement.
308 1.1 mrg Otherwise, return *LOC. */
309 1.1 mrg extern rtx find_replacement (rtx *);
310 1.1 mrg
311 1.1 mrg /* Nonzero if modifying X will affect IN. */
312 1.1 mrg extern int reg_overlap_mentioned_for_reload_p (rtx, rtx);
313 1.1 mrg
314 1.1 mrg /* Check the insns before INSN to see if there is a suitable register
315 1.1 mrg containing the same value as GOAL. */
316 1.1 mrg extern rtx find_equiv_reg (rtx, rtx, enum reg_class, int, short *,
317 1.1 mrg int, enum machine_mode);
318 1.1 mrg
319 1.1 mrg /* Return 1 if register REGNO is the subject of a clobber in insn INSN. */
320 1.1 mrg extern int regno_clobbered_p (unsigned int, rtx, enum machine_mode, int);
321 1.1 mrg
322 1.1 mrg /* Return 1 if X is an operand of an insn that is being earlyclobbered. */
323 1.1 mrg extern int earlyclobber_operand_p (rtx);
324 1.1 mrg
325 1.1 mrg /* Record one reload that needs to be performed. */
326 1.1 mrg extern int push_reload (rtx, rtx, rtx *, rtx *, enum reg_class,
327 1.1 mrg enum machine_mode, enum machine_mode,
328 1.1 mrg int, int, int, enum reload_type);
329 1.1 mrg
330 1.1 mrg /* Functions in postreload.c: */
331 1.1 mrg extern void reload_cse_regs (rtx);
332 1.1 mrg
333 1.1 mrg /* Functions in reload1.c: */
334 1.1 mrg
335 1.1 mrg /* Initialize the reload pass once per compilation. */
336 1.1 mrg extern void init_reload (void);
337 1.1 mrg
338 1.1 mrg /* The reload pass itself. */
339 1.1 mrg extern int reload (rtx, int);
340 1.1 mrg
341 1.1 mrg /* Mark the slots in regs_ever_live for the hard regs
342 1.1 mrg used by pseudo-reg number REGNO. */
343 1.1 mrg extern void mark_home_live (int);
344 1.1 mrg
345 1.1 mrg /* Scan X and replace any eliminable registers (such as fp) with a
346 1.1 mrg replacement (such as sp), plus an offset. */
347 1.1 mrg extern rtx eliminate_regs (rtx, enum machine_mode, rtx);
348 1.1 mrg extern bool elimination_target_reg_p (rtx);
349 1.1 mrg
350 1.1 mrg /* Deallocate the reload register used by reload number R. */
351 1.1 mrg extern void deallocate_reload_reg (int r);
352 1.1 mrg
353 1.1 mrg /* True if caller-save has been reinitialized. */
354 1.1 mrg extern bool caller_save_initialized_p;
355 1.1 mrg
356 1.1 mrg /* Functions in caller-save.c: */
357 1.1 mrg
358 1.1 mrg /* Initialize for caller-save. */
359 1.1 mrg extern void init_caller_save (void);
360 1.1 mrg
361 1.1 mrg /* Initialize save areas by showing that we haven't allocated any yet. */
362 1.1 mrg extern void init_save_areas (void);
363 1.1 mrg
364 1.1 mrg /* Allocate save areas for any hard registers that might need saving. */
365 1.1 mrg extern void setup_save_areas (void);
366 1.1 mrg
367 1.1 mrg /* Find the places where hard regs are live across calls and save them. */
368 1.1 mrg extern void save_call_clobbered_regs (void);
369 1.1 mrg
370 1.1 mrg /* Replace (subreg (reg)) with the appropriate (reg) for any operands. */
371 1.1 mrg extern void cleanup_subreg_operands (rtx);
372 1.1 mrg
373 1.1 mrg /* Debugging support. */
374 1.1 mrg extern void debug_reload_to_stream (FILE *);
375 1.1 mrg extern void debug_reload (void);
376 1.1 mrg
377 1.1 mrg /* Compute the actual register we should reload to, in case we're
378 1.1 mrg reloading to/from a register that is wider than a word. */
379 1.1 mrg extern rtx reload_adjust_reg_for_mode (rtx, enum machine_mode);
380