* config/avr/lib1funcs.S (__ashrdi3, __lshrdi3, __ashldi3)
[official-gcc.git] / gcc / lra-int.h
blob98f2ff709b756952c00a490887717662d837bf1f
1 /* Local Register Allocator (LRA) intercommunication header file.
2 Copyright (C) 2010-2013 Free Software Foundation, Inc.
3 Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3. If not see
19 <http://www.gnu.org/licenses/>. */
21 #include "lra.h"
22 #include "bitmap.h"
23 #include "recog.h"
24 #include "insn-attr.h"
25 #include "insn-codes.h"
27 #define lra_assert(c) gcc_checking_assert (c)
29 /* The parameter used to prevent infinite reloading for an insn. Each
30 insn operands might require a reload and, if it is a memory, its
31 base and index registers might require a reload too. */
32 #define LRA_MAX_INSN_RELOADS (MAX_RECOG_OPERANDS * 3)
34 /* Return the hard register which given pseudo REGNO assigned to.
35 Negative value means that the register got memory or we don't know
36 allocation yet. */
37 static inline int
38 lra_get_regno_hard_regno (int regno)
40 resize_reg_info ();
41 return reg_renumber[regno];
44 typedef struct lra_live_range *lra_live_range_t;
46 /* The structure describes program points where a given pseudo lives.
47 The live ranges can be used to find conflicts with other pseudos.
48 If the live ranges of two pseudos are intersected, the pseudos are
49 in conflict. */
50 struct lra_live_range
52 /* Pseudo regno whose live range is described by given
53 structure. */
54 int regno;
55 /* Program point range. */
56 int start, finish;
57 /* Next structure describing program points where the pseudo
58 lives. */
59 lra_live_range_t next;
60 /* Pointer to structures with the same start. */
61 lra_live_range_t start_next;
64 typedef struct lra_copy *lra_copy_t;
66 /* Copy between pseudos which affects assigning hard registers. */
67 struct lra_copy
69 /* True if regno1 is the destination of the copy. */
70 bool regno1_dest_p;
71 /* Execution frequency of the copy. */
72 int freq;
73 /* Pseudos connected by the copy. REGNO1 < REGNO2. */
74 int regno1, regno2;
75 /* Next copy with correspondingly REGNO1 and REGNO2. */
76 lra_copy_t regno1_next, regno2_next;
79 /* Common info about a register (pseudo or hard register). */
80 struct lra_reg
82 /* Bitmap of UIDs of insns (including debug insns) referring the
83 reg. */
84 bitmap_head insn_bitmap;
85 /* The following fields are defined only for pseudos. */
86 /* Hard registers with which the pseudo conflicts. */
87 HARD_REG_SET conflict_hard_regs;
88 /* We assign hard registers to reload pseudos which can occur in few
89 places. So two hard register preferences are enough for them.
90 The following fields define the preferred hard registers. If
91 there are no such hard registers the first field value is
92 negative. If there is only one preferred hard register, the 2nd
93 field is negative. */
94 int preferred_hard_regno1, preferred_hard_regno2;
95 /* Profits to use the corresponding preferred hard registers. If
96 the both hard registers defined, the first hard register has not
97 less profit than the second one. */
98 int preferred_hard_regno_profit1, preferred_hard_regno_profit2;
99 #ifdef STACK_REGS
100 /* True if the pseudo should not be assigned to a stack register. */
101 bool no_stack_p;
102 #endif
103 #ifdef ENABLE_CHECKING
104 /* True if the pseudo crosses a call. It is setup in lra-lives.c
105 and used to check that the pseudo crossing a call did not get a
106 call used hard register. */
107 bool call_p;
108 #endif
109 /* Number of references and execution frequencies of the register in
110 *non-debug* insns. */
111 int nrefs, freq;
112 int last_reload;
113 /* Regno used to undo the inheritance. It can be non-zero only
114 between couple of inheritance and undo inheritance passes. */
115 int restore_regno;
116 /* Value holding by register. If the pseudos have the same value
117 they do not conflict. */
118 int val;
119 /* These members are set up in lra-lives.c and updated in
120 lra-coalesce.c. */
121 /* The biggest size mode in which each pseudo reg is referred in
122 whole function (possibly via subreg). */
123 enum machine_mode biggest_mode;
124 /* Live ranges of the pseudo. */
125 lra_live_range_t live_ranges;
126 /* This member is set up in lra-lives.c for subsequent
127 assignments. */
128 lra_copy_t copies;
131 /* References to the common info about each register. */
132 extern struct lra_reg *lra_reg_info;
134 /* Static info about each insn operand (common for all insns with the
135 same ICODE). Warning: if the structure definition is changed, the
136 initializer for debug_operand_data in lra.c should be changed
137 too. */
138 struct lra_operand_data
140 /* The machine description constraint string of the operand. */
141 const char *constraint;
142 /* It is taken only from machine description (which is different
143 from recog_data.operand_mode) and can be of VOIDmode. */
144 ENUM_BITFIELD(machine_mode) mode : 16;
145 /* The type of the operand (in/out/inout). */
146 ENUM_BITFIELD (op_type) type : 8;
147 /* Through if accessed through STRICT_LOW. */
148 unsigned int strict_low : 1;
149 /* True if the operand is an operator. */
150 unsigned int is_operator : 1;
151 /* True if there is an early clobber alternative for this operand.
152 This field is set up every time when corresponding
153 operand_alternative in lra_static_insn_data is set up. */
154 unsigned int early_clobber : 1;
155 /* True if the operand is an address. */
156 unsigned int is_address : 1;
159 /* Info about register occurrence in an insn. */
160 struct lra_insn_reg
162 /* The biggest mode through which the insn refers to the register
163 occurrence (remember the register can be accessed through a
164 subreg in the insn). */
165 ENUM_BITFIELD(machine_mode) biggest_mode : 16;
166 /* The type of the corresponding operand which is the register. */
167 ENUM_BITFIELD (op_type) type : 8;
168 /* True if the reg is accessed through a subreg and the subreg is
169 just a part of the register. */
170 unsigned int subreg_p : 1;
171 /* True if there is an early clobber alternative for this
172 operand. */
173 unsigned int early_clobber : 1;
174 /* The corresponding regno of the register. */
175 int regno;
176 /* Next reg info of the same insn. */
177 struct lra_insn_reg *next;
180 /* Static part (common info for insns with the same ICODE) of LRA
181 internal insn info. It exists in at most one exemplar for each
182 non-negative ICODE. There is only one exception. Each asm insn has
183 own structure. Warning: if the structure definition is changed,
184 the initializer for debug_insn_static_data in lra.c should be
185 changed too. */
186 struct lra_static_insn_data
188 /* Static info about each insn operand. */
189 struct lra_operand_data *operand;
190 /* Each duplication refers to the number of the corresponding
191 operand which is duplicated. */
192 int *dup_num;
193 /* The number of an operand marked as commutative, -1 otherwise. */
194 int commutative;
195 /* Number of operands, duplications, and alternatives of the
196 insn. */
197 char n_operands;
198 char n_dups;
199 char n_alternatives;
200 /* Insns in machine description (or clobbers in asm) may contain
201 explicit hard regs which are not operands. The following list
202 describes such hard registers. */
203 struct lra_insn_reg *hard_regs;
204 /* Array [n_alternatives][n_operand] of static constraint info for
205 given operand in given alternative. This info can be changed if
206 the target reg info is changed. */
207 struct operand_alternative *operand_alternative;
210 /* LRA internal info about an insn (LRA internal insn
211 representation). */
212 struct lra_insn_recog_data
214 /* The insn code. */
215 int icode;
216 /* The insn itself. */
217 rtx insn;
218 /* Common data for insns with the same ICODE. Asm insns (their
219 ICODE is negative) do not share such structures. */
220 struct lra_static_insn_data *insn_static_data;
221 /* Two arrays of size correspondingly equal to the operand and the
222 duplication numbers: */
223 rtx **operand_loc; /* The operand locations, NULL if no operands. */
224 rtx **dup_loc; /* The dup locations, NULL if no dups. */
225 /* Number of hard registers implicitly used in given call insn. The
226 value can be NULL or points to array of the hard register numbers
227 ending with a negative value. */
228 int *arg_hard_regs;
229 /* Alternative enabled for the insn. NULL for debug insns. */
230 bool *alternative_enabled_p;
231 /* The alternative should be used for the insn, -1 if invalid, or we
232 should try to use any alternative, or the insn is a debug
233 insn. */
234 int used_insn_alternative;
235 /* The following member value is always NULL for a debug insn. */
236 struct lra_insn_reg *regs;
239 typedef struct lra_insn_recog_data *lra_insn_recog_data_t;
241 /* Whether the clobber is used temporary in LRA. */
242 #define LRA_TEMP_CLOBBER_P(x) \
243 (RTL_FLAG_CHECK1 ("TEMP_CLOBBER_P", (x), CLOBBER)->unchanging)
245 /* Cost factor for each additional reload and maximal cost reject for
246 insn reloads. One might ask about such strange numbers. Their
247 values occurred historically from former reload pass. */
248 #define LRA_LOSER_COST_FACTOR 6
249 #define LRA_MAX_REJECT 600
251 /* Maximum allowed number of constraint pass iterations after the last
252 spill pass. It is for preventing LRA cycling in a bug case. */
253 #define LRA_MAX_CONSTRAINT_ITERATION_NUMBER 30
255 /* The maximal number of inheritance/split passes in LRA. It should
256 be more 1 in order to perform caller saves transformations and much
257 less MAX_CONSTRAINT_ITERATION_NUMBER to prevent LRA to do as many
258 as permitted constraint passes in some complicated cases. The
259 first inheritance/split pass has a biggest impact on generated code
260 quality. Each subsequent affects generated code in less degree.
261 For example, the 3rd pass does not change generated SPEC2000 code
262 at all on x86-64. */
263 #define LRA_MAX_INHERITANCE_PASSES 2
265 #if LRA_MAX_INHERITANCE_PASSES <= 0 \
266 || LRA_MAX_INHERITANCE_PASSES >= LRA_MAX_CONSTRAINT_ITERATION_NUMBER - 8
267 #error wrong LRA_MAX_INHERITANCE_PASSES value
268 #endif
270 /* lra.c: */
272 extern FILE *lra_dump_file;
274 extern bool lra_reg_spill_p;
276 extern HARD_REG_SET lra_no_alloc_regs;
278 extern int lra_insn_recog_data_len;
279 extern lra_insn_recog_data_t *lra_insn_recog_data;
281 extern int lra_curr_reload_num;
283 extern void lra_push_insn (rtx);
284 extern void lra_push_insn_by_uid (unsigned int);
285 extern void lra_push_insn_and_update_insn_regno_info (rtx);
286 extern rtx lra_pop_insn (void);
287 extern unsigned int lra_insn_stack_length (void);
289 extern rtx lra_create_new_reg_with_unique_value (enum machine_mode, rtx,
290 enum reg_class, const char *);
291 extern void lra_set_regno_unique_value (int);
292 extern void lra_invalidate_insn_data (rtx);
293 extern void lra_set_insn_deleted (rtx);
294 extern void lra_delete_dead_insn (rtx);
295 extern void lra_emit_add (rtx, rtx, rtx);
296 extern void lra_emit_move (rtx, rtx);
297 extern void lra_update_dups (lra_insn_recog_data_t, signed char *);
299 extern void lra_process_new_insns (rtx, rtx, rtx, const char *);
301 extern lra_insn_recog_data_t lra_set_insn_recog_data (rtx);
302 extern lra_insn_recog_data_t lra_update_insn_recog_data (rtx);
303 extern void lra_set_used_insn_alternative (rtx, int);
304 extern void lra_set_used_insn_alternative_by_uid (int, int);
306 extern void lra_invalidate_insn_regno_info (rtx);
307 extern void lra_update_insn_regno_info (rtx);
308 extern struct lra_insn_reg *lra_get_insn_regs (int);
310 extern void lra_free_copies (void);
311 extern void lra_create_copy (int, int, int);
312 extern lra_copy_t lra_get_copy (int);
313 extern bool lra_former_scratch_p (int);
314 extern bool lra_former_scratch_operand_p (rtx, int);
316 extern int lra_new_regno_start;
317 extern int lra_constraint_new_regno_start;
318 extern bitmap_head lra_inheritance_pseudos;
319 extern bitmap_head lra_split_regs;
320 extern bitmap_head lra_optional_reload_pseudos;
321 extern int lra_constraint_new_insn_uid_start;
323 /* lra-constraints.c: */
325 extern int lra_constraint_offset (int, enum machine_mode);
327 extern int lra_constraint_iter;
328 extern int lra_constraint_iter_after_spill;
329 extern bool lra_risky_transformations_p;
330 extern int lra_inheritance_iter;
331 extern int lra_undo_inheritance_iter;
332 extern bool lra_constraints (bool);
333 extern void lra_constraints_init (void);
334 extern void lra_constraints_finish (void);
335 extern void lra_inheritance (void);
336 extern bool lra_undo_inheritance (void);
338 /* lra-lives.c: */
340 extern int lra_live_max_point;
341 extern int *lra_point_freq;
343 extern int lra_hard_reg_usage[FIRST_PSEUDO_REGISTER];
345 extern int lra_live_range_iter;
346 extern void lra_create_live_ranges (bool);
347 extern lra_live_range_t lra_copy_live_range_list (lra_live_range_t);
348 extern lra_live_range_t lra_merge_live_ranges (lra_live_range_t,
349 lra_live_range_t);
350 extern bool lra_intersected_live_ranges_p (lra_live_range_t,
351 lra_live_range_t);
352 extern void lra_print_live_range_list (FILE *, lra_live_range_t);
353 extern void lra_debug_live_range_list (lra_live_range_t);
354 extern void lra_debug_pseudo_live_ranges (int);
355 extern void lra_debug_live_ranges (void);
356 extern void lra_clear_live_ranges (void);
357 extern void lra_live_ranges_init (void);
358 extern void lra_live_ranges_finish (void);
359 extern void lra_setup_reload_pseudo_preferenced_hard_reg (int, int, int);
361 /* lra-assigns.c: */
363 extern void lra_setup_reg_renumber (int, int, bool);
364 extern bool lra_assign (void);
367 /* lra-coalesce.c: */
369 extern int lra_coalesce_iter;
370 extern bool lra_coalesce (void);
372 /* lra-spills.c: */
374 extern bool lra_need_for_spills_p (void);
375 extern void lra_spill (void);
376 extern void lra_final_code_change (void);
379 /* lra-elimination.c: */
381 extern void lra_debug_elim_table (void);
382 extern int lra_get_elimination_hard_regno (int);
383 extern rtx lra_eliminate_regs_1 (rtx, enum machine_mode, bool, bool, bool);
384 extern void lra_eliminate (bool);
386 extern void lra_eliminate_reg_if_possible (rtx *);
390 /* Update insn operands which are duplication of NOP operand. The
391 insn is represented by its LRA internal representation ID. */
392 static inline void
393 lra_update_dup (lra_insn_recog_data_t id, int nop)
395 int i;
396 struct lra_static_insn_data *static_id = id->insn_static_data;
398 for (i = 0; i < static_id->n_dups; i++)
399 if (static_id->dup_num[i] == nop)
400 *id->dup_loc[i] = *id->operand_loc[nop];
403 /* Process operator duplications in insn with ID. We do it after the
404 operands processing. Generally speaking, we could do this probably
405 simultaneously with operands processing because a common practice
406 is to enumerate the operators after their operands. */
407 static inline void
408 lra_update_operator_dups (lra_insn_recog_data_t id)
410 int i;
411 struct lra_static_insn_data *static_id = id->insn_static_data;
413 for (i = 0; i < static_id->n_dups; i++)
415 int ndup = static_id->dup_num[i];
417 if (static_id->operand[ndup].is_operator)
418 *id->dup_loc[i] = *id->operand_loc[ndup];
422 /* Return info about INSN. Set up the info if it is not done yet. */
423 static inline lra_insn_recog_data_t
424 lra_get_insn_recog_data (rtx insn)
426 lra_insn_recog_data_t data;
427 unsigned int uid = INSN_UID (insn);
429 if (lra_insn_recog_data_len > (int) uid
430 && (data = lra_insn_recog_data[uid]) != NULL)
432 /* Check that we did not change insn without updating the insn
433 info. */
434 lra_assert (data->insn == insn
435 && (INSN_CODE (insn) < 0
436 || data->icode == INSN_CODE (insn)));
437 return data;
439 return lra_set_insn_recog_data (insn);
444 struct target_lra_int
446 /* Map INSN_UID -> the operand alternative data (NULL if unknown).
447 We assume that this data is valid until register info is changed
448 because classes in the data can be changed. */
449 struct operand_alternative *x_op_alt_data[LAST_INSN_CODE];
452 extern struct target_lra_int default_target_lra_int;
453 #if SWITCHABLE_TARGET
454 extern struct target_lra_int *this_target_lra_int;
455 #else
456 #define this_target_lra_int (&default_target_lra_int)
457 #endif
459 #define op_alt_data (this_target_lra_int->x_op_alt_data)