xref: /dflybsd-src/contrib/gcc-8.0/gcc/ira.h (revision 38fd149817dfbff97799f62fcb70be98c4e32523)
1*38fd1498Szrj /* Communication between the Integrated Register Allocator (IRA) and
2*38fd1498Szrj    the rest of the compiler.
3*38fd1498Szrj    Copyright (C) 2006-2018 Free Software Foundation, Inc.
4*38fd1498Szrj    Contributed by Vladimir Makarov <vmakarov@redhat.com>.
5*38fd1498Szrj 
6*38fd1498Szrj This file is part of GCC.
7*38fd1498Szrj 
8*38fd1498Szrj GCC is free software; you can redistribute it and/or modify it under
9*38fd1498Szrj the terms of the GNU General Public License as published by the Free
10*38fd1498Szrj Software Foundation; either version 3, or (at your option) any later
11*38fd1498Szrj version.
12*38fd1498Szrj 
13*38fd1498Szrj GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14*38fd1498Szrj WARRANTY; without even the implied warranty of MERCHANTABILITY or
15*38fd1498Szrj FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16*38fd1498Szrj for more details.
17*38fd1498Szrj 
18*38fd1498Szrj You should have received a copy of the GNU General Public License
19*38fd1498Szrj along with GCC; see the file COPYING3.  If not see
20*38fd1498Szrj <http://www.gnu.org/licenses/>.  */
21*38fd1498Szrj 
22*38fd1498Szrj #ifndef GCC_IRA_H
23*38fd1498Szrj #define GCC_IRA_H
24*38fd1498Szrj 
25*38fd1498Szrj #include "emit-rtl.h"
26*38fd1498Szrj 
27*38fd1498Szrj /* True when we use LRA instead of reload pass for the current
28*38fd1498Szrj    function.  */
29*38fd1498Szrj extern bool ira_use_lra_p;
30*38fd1498Szrj 
31*38fd1498Szrj /* True if we have allocno conflicts.  It is false for non-optimized
32*38fd1498Szrj    mode or when the conflict table is too big.  */
33*38fd1498Szrj extern bool ira_conflicts_p;
34*38fd1498Szrj 
35*38fd1498Szrj struct target_ira
36*38fd1498Szrj {
37*38fd1498Szrj   /* Map: hard register number -> allocno class it belongs to.  If the
38*38fd1498Szrj      corresponding class is NO_REGS, the hard register is not available
39*38fd1498Szrj      for allocation.  */
40*38fd1498Szrj   enum reg_class x_ira_hard_regno_allocno_class[FIRST_PSEUDO_REGISTER];
41*38fd1498Szrj 
42*38fd1498Szrj   /* Number of allocno classes.  Allocno classes are register classes
43*38fd1498Szrj      which can be used for allocations of allocnos.  */
44*38fd1498Szrj   int x_ira_allocno_classes_num;
45*38fd1498Szrj 
46*38fd1498Szrj   /* The array containing allocno classes.  Only first
47*38fd1498Szrj      IRA_ALLOCNO_CLASSES_NUM elements are used for this.  */
48*38fd1498Szrj   enum reg_class x_ira_allocno_classes[N_REG_CLASSES];
49*38fd1498Szrj 
50*38fd1498Szrj   /* Map of all register classes to corresponding allocno classes
51*38fd1498Szrj      containing the given class.  If given class is not a subset of an
52*38fd1498Szrj      allocno class, we translate it into the cheapest allocno class.  */
53*38fd1498Szrj   enum reg_class x_ira_allocno_class_translate[N_REG_CLASSES];
54*38fd1498Szrj 
55*38fd1498Szrj   /* Number of pressure classes.  Pressure classes are register
56*38fd1498Szrj      classes for which we calculate register pressure.  */
57*38fd1498Szrj   int x_ira_pressure_classes_num;
58*38fd1498Szrj 
59*38fd1498Szrj   /* The array containing pressure classes.  Only first
60*38fd1498Szrj      IRA_PRESSURE_CLASSES_NUM elements are used for this.  */
61*38fd1498Szrj   enum reg_class x_ira_pressure_classes[N_REG_CLASSES];
62*38fd1498Szrj 
63*38fd1498Szrj   /* Map of all register classes to corresponding pressure classes
64*38fd1498Szrj      containing the given class.  If given class is not a subset of an
65*38fd1498Szrj      pressure class, we translate it into the cheapest pressure
66*38fd1498Szrj      class.  */
67*38fd1498Szrj   enum reg_class x_ira_pressure_class_translate[N_REG_CLASSES];
68*38fd1498Szrj 
69*38fd1498Szrj   /* Biggest pressure register class containing stack registers.
70*38fd1498Szrj      NO_REGS if there are no stack registers.  */
71*38fd1498Szrj   enum reg_class x_ira_stack_reg_pressure_class;
72*38fd1498Szrj 
73*38fd1498Szrj   /* Maps: register class x machine mode -> maximal/minimal number of
74*38fd1498Szrj      hard registers of given class needed to store value of given
75*38fd1498Szrj      mode.  */
76*38fd1498Szrj   unsigned char x_ira_reg_class_max_nregs[N_REG_CLASSES][MAX_MACHINE_MODE];
77*38fd1498Szrj   unsigned char x_ira_reg_class_min_nregs[N_REG_CLASSES][MAX_MACHINE_MODE];
78*38fd1498Szrj 
79*38fd1498Szrj   /* Array analogous to target hook TARGET_MEMORY_MOVE_COST.  */
80*38fd1498Szrj   short x_ira_memory_move_cost[MAX_MACHINE_MODE][N_REG_CLASSES][2];
81*38fd1498Szrj 
82*38fd1498Szrj   /* Array of number of hard registers of given class which are
83*38fd1498Szrj      available for the allocation.  The order is defined by the
84*38fd1498Szrj      allocation order.  */
85*38fd1498Szrj   short x_ira_class_hard_regs[N_REG_CLASSES][FIRST_PSEUDO_REGISTER];
86*38fd1498Szrj 
87*38fd1498Szrj   /* The number of elements of the above array for given register
88*38fd1498Szrj      class.  */
89*38fd1498Szrj   int x_ira_class_hard_regs_num[N_REG_CLASSES];
90*38fd1498Szrj 
91*38fd1498Szrj   /* Register class subset relation: TRUE if the first class is a subset
92*38fd1498Szrj      of the second one considering only hard registers available for the
93*38fd1498Szrj      allocation.  */
94*38fd1498Szrj   int x_ira_class_subset_p[N_REG_CLASSES][N_REG_CLASSES];
95*38fd1498Szrj 
96*38fd1498Szrj   /* The biggest class inside of intersection of the two classes (that
97*38fd1498Szrj      is calculated taking only hard registers available for allocation
98*38fd1498Szrj      into account.  If the both classes contain no hard registers
99*38fd1498Szrj      available for allocation, the value is calculated with taking all
100*38fd1498Szrj      hard-registers including fixed ones into account.  */
101*38fd1498Szrj   enum reg_class x_ira_reg_class_subset[N_REG_CLASSES][N_REG_CLASSES];
102*38fd1498Szrj 
103*38fd1498Szrj   /* True if the two classes (that is calculated taking only hard
104*38fd1498Szrj      registers available for allocation into account; are
105*38fd1498Szrj      intersected.  */
106*38fd1498Szrj   bool x_ira_reg_classes_intersect_p[N_REG_CLASSES][N_REG_CLASSES];
107*38fd1498Szrj 
108*38fd1498Szrj   /* If class CL has a single allocatable register of mode M,
109*38fd1498Szrj      index [CL][M] gives the number of that register, otherwise it is -1.  */
110*38fd1498Szrj   short x_ira_class_singleton[N_REG_CLASSES][MAX_MACHINE_MODE];
111*38fd1498Szrj 
112*38fd1498Szrj   /* Function specific hard registers can not be used for the register
113*38fd1498Szrj      allocation.  */
114*38fd1498Szrj   HARD_REG_SET x_ira_no_alloc_regs;
115*38fd1498Szrj 
116*38fd1498Szrj   /* Array whose values are hard regset of hard registers available for
117*38fd1498Szrj      the allocation of given register class whose targetm.hard_regno_mode_ok
118*38fd1498Szrj      values for given mode are false.  */
119*38fd1498Szrj   HARD_REG_SET x_ira_prohibited_class_mode_regs[N_REG_CLASSES][NUM_MACHINE_MODES];
120*38fd1498Szrj };
121*38fd1498Szrj 
122*38fd1498Szrj extern struct target_ira default_target_ira;
123*38fd1498Szrj #if SWITCHABLE_TARGET
124*38fd1498Szrj extern struct target_ira *this_target_ira;
125*38fd1498Szrj #else
126*38fd1498Szrj #define this_target_ira (&default_target_ira)
127*38fd1498Szrj #endif
128*38fd1498Szrj 
129*38fd1498Szrj #define ira_hard_regno_allocno_class \
130*38fd1498Szrj   (this_target_ira->x_ira_hard_regno_allocno_class)
131*38fd1498Szrj #define ira_allocno_classes_num \
132*38fd1498Szrj   (this_target_ira->x_ira_allocno_classes_num)
133*38fd1498Szrj #define ira_allocno_classes \
134*38fd1498Szrj   (this_target_ira->x_ira_allocno_classes)
135*38fd1498Szrj #define ira_allocno_class_translate \
136*38fd1498Szrj   (this_target_ira->x_ira_allocno_class_translate)
137*38fd1498Szrj #define ira_pressure_classes_num \
138*38fd1498Szrj   (this_target_ira->x_ira_pressure_classes_num)
139*38fd1498Szrj #define ira_pressure_classes \
140*38fd1498Szrj   (this_target_ira->x_ira_pressure_classes)
141*38fd1498Szrj #define ira_pressure_class_translate \
142*38fd1498Szrj   (this_target_ira->x_ira_pressure_class_translate)
143*38fd1498Szrj #define ira_stack_reg_pressure_class \
144*38fd1498Szrj   (this_target_ira->x_ira_stack_reg_pressure_class)
145*38fd1498Szrj #define ira_reg_class_max_nregs \
146*38fd1498Szrj   (this_target_ira->x_ira_reg_class_max_nregs)
147*38fd1498Szrj #define ira_reg_class_min_nregs \
148*38fd1498Szrj   (this_target_ira->x_ira_reg_class_min_nregs)
149*38fd1498Szrj #define ira_memory_move_cost \
150*38fd1498Szrj   (this_target_ira->x_ira_memory_move_cost)
151*38fd1498Szrj #define ira_class_hard_regs \
152*38fd1498Szrj   (this_target_ira->x_ira_class_hard_regs)
153*38fd1498Szrj #define ira_class_hard_regs_num \
154*38fd1498Szrj   (this_target_ira->x_ira_class_hard_regs_num)
155*38fd1498Szrj #define ira_class_subset_p \
156*38fd1498Szrj   (this_target_ira->x_ira_class_subset_p)
157*38fd1498Szrj #define ira_reg_class_subset \
158*38fd1498Szrj   (this_target_ira->x_ira_reg_class_subset)
159*38fd1498Szrj #define ira_reg_classes_intersect_p \
160*38fd1498Szrj   (this_target_ira->x_ira_reg_classes_intersect_p)
161*38fd1498Szrj #define ira_class_singleton \
162*38fd1498Szrj   (this_target_ira->x_ira_class_singleton)
163*38fd1498Szrj #define ira_no_alloc_regs \
164*38fd1498Szrj   (this_target_ira->x_ira_no_alloc_regs)
165*38fd1498Szrj #define ira_prohibited_class_mode_regs \
166*38fd1498Szrj   (this_target_ira->x_ira_prohibited_class_mode_regs)
167*38fd1498Szrj 
168*38fd1498Szrj /* Major structure describing equivalence info for a pseudo.  */
169*38fd1498Szrj struct ira_reg_equiv_s
170*38fd1498Szrj {
171*38fd1498Szrj   /* True if we can use this equivalence.  */
172*38fd1498Szrj   bool defined_p;
173*38fd1498Szrj   /* True if the usage of the equivalence is profitable.  */
174*38fd1498Szrj   bool profitable_p;
175*38fd1498Szrj   /* Equiv. memory, constant, invariant, and initializing insns of
176*38fd1498Szrj      given pseudo-register or NULL_RTX.  */
177*38fd1498Szrj   rtx memory;
178*38fd1498Szrj   rtx constant;
179*38fd1498Szrj   rtx invariant;
180*38fd1498Szrj   /* Always NULL_RTX if defined_p is false.  */
181*38fd1498Szrj   rtx_insn_list *init_insns;
182*38fd1498Szrj };
183*38fd1498Szrj 
184*38fd1498Szrj /* The length of the following array.  */
185*38fd1498Szrj extern int ira_reg_equiv_len;
186*38fd1498Szrj 
187*38fd1498Szrj /* Info about equiv. info for each register.  */
188*38fd1498Szrj extern struct ira_reg_equiv_s *ira_reg_equiv;
189*38fd1498Szrj 
190*38fd1498Szrj extern void ira_init_once (void);
191*38fd1498Szrj extern void ira_init (void);
192*38fd1498Szrj extern void ira_setup_eliminable_regset (void);
193*38fd1498Szrj extern rtx ira_eliminate_regs (rtx, machine_mode);
194*38fd1498Szrj extern void ira_set_pseudo_classes (bool, FILE *);
195*38fd1498Szrj extern void ira_expand_reg_equiv (void);
196*38fd1498Szrj extern void ira_update_equiv_info_by_shuffle_insn (int, int, rtx_insn *);
197*38fd1498Szrj 
198*38fd1498Szrj extern void ira_sort_regnos_for_alter_reg (int *, int, machine_mode *);
199*38fd1498Szrj extern void ira_mark_allocation_change (int);
200*38fd1498Szrj extern void ira_mark_memory_move_deletion (int, int);
201*38fd1498Szrj extern bool ira_reassign_pseudos (int *, int, HARD_REG_SET, HARD_REG_SET *,
202*38fd1498Szrj 				  HARD_REG_SET *, bitmap);
203*38fd1498Szrj extern rtx ira_reuse_stack_slot (int, poly_uint64, poly_uint64);
204*38fd1498Szrj extern void ira_mark_new_stack_slot (rtx, int, poly_uint64);
205*38fd1498Szrj extern bool ira_better_spill_reload_regno_p (int *, int *, rtx, rtx, rtx_insn *);
206*38fd1498Szrj extern bool ira_bad_reload_regno (int, rtx, rtx);
207*38fd1498Szrj 
208*38fd1498Szrj extern void ira_adjust_equiv_reg_cost (unsigned, int);
209*38fd1498Szrj 
210*38fd1498Szrj /* ira-costs.c */
211*38fd1498Szrj extern void ira_costs_c_finalize (void);
212*38fd1498Szrj 
213*38fd1498Szrj /* Spilling static chain pseudo may result in generation of wrong
214*38fd1498Szrj    non-local goto code using frame-pointer to address saved stack
215*38fd1498Szrj    pointer value after restoring old frame pointer value.  The
216*38fd1498Szrj    function returns TRUE if REGNO is such a static chain pseudo.  */
217*38fd1498Szrj static inline bool
non_spilled_static_chain_regno_p(int regno)218*38fd1498Szrj non_spilled_static_chain_regno_p (int regno)
219*38fd1498Szrj {
220*38fd1498Szrj   return (cfun->static_chain_decl && crtl->has_nonlocal_goto
221*38fd1498Szrj 	  && REG_EXPR (regno_reg_rtx[regno]) == cfun->static_chain_decl);
222*38fd1498Szrj }
223*38fd1498Szrj 
224*38fd1498Szrj #endif /* GCC_IRA_H */
225