GCC Middle and Back End API Reference
ira-costs.c File Reference

Data Structures

struct  costs
struct  cost_classes
struct  cost_classes_hasher

Typedefs

typedef struct cost_classescost_classes_t
typedef struct cost_classesconst_cost_classes_t

Functions

static void initiate_regno_cost_classes ()
static cost_classes_t setup_cost_classes ()
static void setup_regno_cost_classes_by_aclass ()
static void setup_regno_cost_classes_by_mode ()
static void finish_regno_cost_classes ()
static int copy_cost (rtx x, enum machine_mode mode, reg_class_t rclass, bool to_p, secondary_reload_info *prev_sri)
static void record_reg_classes (int n_alts, int n_ops, rtx *ops, enum machine_mode *modes, const char **constraints, rtx insn, enum reg_class *pref)
static bool ok_for_index_p_nonstrict ()
static bool ok_for_base_p_nonstrict (rtx reg, enum machine_mode mode, addr_space_t as, enum rtx_code outer_code, enum rtx_code index_code)
static void record_address_regs (enum machine_mode mode, addr_space_t as, rtx x, int context, enum rtx_code outer_code, enum rtx_code index_code, int scale)
static void record_operand_costs ()
static rtx scan_one_insn ()
static void print_allocno_costs ()
static void print_pseudo_costs ()
static void process_bb_for_costs ()
static void process_bb_node_for_costs ()
static void find_costs_and_classes ()
static void process_bb_node_for_hard_reg_moves ()
static void setup_allocno_class_and_costs ()
void ira_init_costs_once ()
static void free_ira_costs ()
void ira_init_costs ()
void ira_finish_costs_once ()
static void init_costs ()
static void finish_costs ()
void ira_costs ()
void ira_set_pseudo_classes ()
void ira_tune_allocno_costs ()
void ira_adjust_equiv_reg_cost ()

Variables

static bool pseudo_classes_defined_p = false
static bool allocno_p
static int cost_elements_num
static struct costscosts
static struct coststotal_allocno_costs
static int struct_costs_size
static enum reg_class * pref
static enum reg_class * pref_buffer
static enum reg_class * regno_aclass
static int * regno_equiv_gains
static int frequency
static cost_classes_tregno_cost_classes
static hash_table
< cost_classes_hasher
cost_classes_htab
static cost_classes_t cost_classes_aclass_cache [N_REG_CLASSES]
static cost_classes_t cost_classes_mode_cache [MAX_MACHINE_MODE]

Typedef Documentation

typedef struct cost_classes* cost_classes_t
Types of pointers to the structure above.   

Function Documentation

static int copy_cost ( rtx  x,
enum machine_mode  mode,
reg_class_t  rclass,
bool  to_p,
secondary_reload_info prev_sri 
)
static
Compute the cost of loading X into (if TO_P is TRUE) or from (if
   TO_P is FALSE) a register of class RCLASS in mode MODE.  X must not
   be a pseudo register.   

References secondary_reload_info::extra_cost, ira_init_register_move_cost_if_necessary(), secondary_reload_info::prev_sri, and targetm.

Referenced by record_reg_classes().

static void finish_costs ( )
static
Common finalization function for ira_costs and
   ira_set_pseudo_classes.   

References finish_subregs_of_mode(), ira_free(), pref_buffer, regno_aclass, and regno_equiv_gains.

Referenced by ira_costs(), and ira_set_pseudo_classes().

static void finish_regno_cost_classes ( )
static
Finilize info about the cost classes for each pseudo.   

References hash_table< Descriptor, Allocator >::dispose(), and ira_free().

Referenced by ira_costs(), and ira_set_pseudo_classes().

static void free_ira_costs ( )
static
Free allocated temporary cost vectors.   

References free(), and init_cost().

Referenced by ira_finish_costs_once(), and ira_init_costs().

static void init_costs ( )
static
Common initialization function for ira_costs and
   ira_set_pseudo_classes.   

References cost_elements_num, init_subregs_of_mode(), ira_allocate(), max_reg_num(), memset(), pref_buffer, regno_aclass, and regno_equiv_gains.

Referenced by ira_costs(), and ira_set_pseudo_classes().

static void initiate_regno_cost_classes ( )
static
Initialize info about the cost classes for each pseudo.   

References hash_table< Descriptor, Allocator >::create(), ira_allocate(), max_reg_num(), and memset().

Referenced by ira_costs(), and ira_set_pseudo_classes().

void ira_adjust_equiv_reg_cost ( )
Add COST to the estimated gain for eliminating REGNO with its
   equivalence.  If COST is zero, record that no such elimination is
   possible.   

References costs::cost, and regno_equiv_gains.

Referenced by calculate_elim_costs_all_insns(), and note_reg_elim_costly().

void ira_costs ( void  )
void ira_finish_costs_once ( void  )
Function called once at the end of compiler work.   

References free_ira_costs().

Referenced by ira_finish_once().

void ira_init_costs ( void  )
This is called each time register related information is
   changed.   

References costs::cost, free_ira_costs(), init_cost(), and costs::mem_cost.

Referenced by ira_init().

void ira_init_costs_once ( void  )
Function called once during compiler work.   

References init_cost().

Referenced by ira_init_once().

void ira_set_pseudo_classes ( )
void ira_tune_allocno_costs ( void  )
Change hard register costs for allocnos which lives through
   function calls.  This is called only when we found all intersected
   calls during building allocno live ranges.   

References costs::cost, ira_allocate_and_set_costs(), and ira_hard_reg_set_intersection_p().

Referenced by ira_build().

static bool ok_for_base_p_nonstrict ( rtx  reg,
enum machine_mode  mode,
addr_space_t  as,
enum rtx_code  outer_code,
enum rtx_code  index_code 
)
inlinestatic
A version of regno_ok_for_base_p for use here, when all
   pseudo-registers should count as OK.  Arguments as for
   regno_ok_for_base_p.   

References ok_for_base_p_1().

Referenced by record_address_regs().

static bool ok_for_index_p_nonstrict ( )
inlinestatic
Wrapper around REGNO_OK_FOR_INDEX_P, to allow pseudo registers.   

Referenced by record_address_regs().

static void print_allocno_costs ( )
static
static void print_pseudo_costs ( )
static
static void process_bb_for_costs ( )
static
Traverse the BB represented by LOOP_TREE_NODE to update the allocno
   costs.   

References frequency, and scan_one_insn().

Referenced by find_costs_and_classes(), and process_bb_node_for_costs().

static void process_bb_node_for_costs ( )
static
Traverse the BB represented by LOOP_TREE_NODE to update the allocno
   costs.   

References ira_loop_tree_node::bb, and process_bb_for_costs().

Referenced by find_costs_and_classes().

static void process_bb_node_for_hard_reg_moves ( )
static
Process moves involving hard regs to modify allocno hard register
   costs.  We can do this only after determining allocno class.  If a
   hard register forms a register class, than moves with the hard
   register are already taken into account in class costs for the
   allocno.   

References ira_loop_tree_node::bb, costs::cost, ira_allocate_and_set_costs(), ira_curr_regno_allocno_map, and ira_init_register_move_cost_if_necessary().

Referenced by setup_allocno_class_and_costs().

static void record_address_regs ( enum machine_mode  mode,
addr_space_t  as,
rtx  x,
int  context,
enum rtx_code  outer_code,
enum rtx_code  index_code,
int  scale 
)
static
Record the pseudo registers we must reload into hard registers in a
   subexpression of a memory address, X.

   If CONTEXT is 0, we are looking at the base part of an address,
   otherwise we are looking at the index part.

   MODE and AS are the mode and address space of the memory reference;
   OUTER_CODE and INDEX_CODE give the context that the rtx appears in.
   These four arguments are passed down to base_reg_class.

   SCALE is twice the amount to multiply the cost by (it is twice so
   we can represent half-cost adjustments).   

References add_cost(), allocno_p, base_reg_class(), cost_classes::classes, costs::cost, ira_curr_regno_allocno_map, ira_init_register_move_cost_if_necessary(), costs::mem_cost, cost_classes::num, ok_for_base_p_nonstrict(), and ok_for_index_p_nonstrict().

Referenced by record_operand_costs(), and scan_one_insn().

static void record_reg_classes ( int  n_alts,
int  n_ops,
rtx ops,
enum machine_mode *  modes,
const char **  constraints,
rtx  insn,
enum reg_class *  pref 
)
static
Record the cost of using memory or hard registers of various
   classes for the operands in INSN.

   N_ALTS is the number of alternatives.
   N_OPS is the number of operands.
   OPS is an array of the operands.
   MODES are the modes of the operands, in case any are VOIDmode.
   CONSTRAINTS are the constraints to use for the operands.  This array
   is modified by this procedure.

   This procedure works alternative by alternative.  For each
   alternative we assume that we will be able to allocate all allocnos
   to their ideal register class and calculate the cost of using that
   alternative.  Then we compute, for each operand that is a
   pseudo-register, the cost of having the allocno allocated to each
   register class and using it in that alternative.  To this cost is
   added the cost of the alternative.

   The cost of each class for this insn is its lowest cost among all
   the alternatives.   

References address_operand(), allocno_p, recog_data_d::alternative_enabled_p, base_reg_class(), cost_classes::classes, copy_cost(), costs::cost, find_reg_note(), find_regno_note(), frequency, ira_curr_regno_allocno_map, ira_init_register_move_cost_if_necessary(), costs::mem_cost, memset(), recog_data_d::n_operands, nr, cost_classes::num, OP_IN, OP_INOUT, OP_OUT, recog_data_d::operand_type, recog_data, reg_fits_class_p(), rtx_equal_p(), skip_alternative(), and struct_costs_size.

Referenced by record_operand_costs().

static rtx scan_one_insn ( )
static
Process one insn INSN.  Scan it and record each time it would save
   code to put a certain allocnos in a certain class.  Return the last
   insn processed, so that the scan can be continued from there.   

References add_cost(), costs::cost, extract_insn(), find_reg_note(), frequency, general_operand(), costs::mem_cost, recog_data_d::n_operands, cost_classes::num, recog_data_d::operand, pref, recog_data, record_address_regs(), record_operand_costs(), REG_N_SETS(), side_effects_p(), and targetm.

Referenced by process_bb_for_costs().

static void setup_allocno_class_and_costs ( )
static
After we find hard register and memory costs for allocnos, define
   its class and modify hard register cost because insns moving
   allocno to/from hard registers.   

References allocno_p, cost_classes::hard_regno_index, cost_classes::index, ira_allocate_cost_vector(), ira_loop_tree_root, ira_set_allocno_class(), ira_traverse_loop_tree(), pref, process_bb_node_for_hard_reg_moves(), and regno_aclass.

Referenced by ira_costs().

static cost_classes_t setup_cost_classes ( )
static
Create new cost classes from cost classes FROM and set up members
   index and hard_regno_index.  Return the new classes.  The function
   implements some common code of two functions
   setup_regno_cost_classes_by_aclass and
   setup_regno_cost_classes_by_mode.   

References cost_classes::classes, cost_classes::hard_regno_index, cost_classes::index, ira_allocate(), and cost_classes::num.

Referenced by setup_regno_cost_classes_by_aclass(), and setup_regno_cost_classes_by_mode().

static void setup_regno_cost_classes_by_aclass ( )
static
Setup cost classes for pseudo REGNO whose allocno class is ACLASS.
   This function is used when we know an initial approximation of
   allocno class of the pseudo already, e.g. on the second iteration
   of class cost calculation or after class cost calculation in
   register-pressure sensitive insn scheduling or register-pressure
   sensitive loop-invariant motion.   

References cost_classes::classes, hash_table< Descriptor, Allocator >::find_slot(), hard_reg_set_subset_p(), cost_classes::num, and setup_cost_classes().

Referenced by find_costs_and_classes().

static void setup_regno_cost_classes_by_mode ( )
static
Setup cost classes for pseudo REGNO with MODE.  Usage of MODE can
   decrease number of cost classes for the pseudo, if hard registers
   of some important classes can not hold a value of MODE.  So the
   pseudo can not get hard register of some important classes and cost
   calculation for such important classes is only waisting CPU
   time.   

References cost_classes::classes, hash_table< Descriptor, Allocator >::find_slot(), hard_reg_set_subset_p(), cost_classes::num, and setup_cost_classes().

Referenced by find_costs_and_classes().


Variable Documentation

bool allocno_p
static
cost_classes_t cost_classes_aclass_cache[N_REG_CLASSES]
static
Map allocno class -> cost classes for pseudo of given allocno
   class.   
hash_table<cost_classes_hasher> cost_classes_htab
static
Hash table of unique cost classes.   
cost_classes_t cost_classes_mode_cache[MAX_MACHINE_MODE]
static
Map mode -> cost classes for pseudo of give mode.   
int cost_elements_num
static
Number of elements in array `costs'.   

Referenced by find_costs_and_classes(), init_costs(), ira_costs(), and ira_set_pseudo_classes().

struct costs* costs
static
Costs of each class for each allocno or pseudo.   

Referenced by setup_profitable_hard_regs().

enum reg_class* pref
static
Record register class preferences of each allocno or pseudo.  Null
   value means no preferences.  It happens on the 1st iteration of the
   cost calculation.   

Referenced by alloc_anon(), find_costs_and_classes(), ira_bad_reload_regno_1(), iv_ca_dump(), rest_of_clean_state(), scan_one_insn(), setup_allocno_class_and_costs(), try_move_mult_to_index(), and update_conflict_hard_reg_costs().

enum reg_class* pref_buffer
static
Allocated buffers for pref.   

Referenced by find_costs_and_classes(), finish_costs(), and init_costs().

bool pseudo_classes_defined_p = false
static
@verbatim IRA hard register and memory cost calculation for allocnos or pseudos.

Copyright (C) 2006-2013 Free Software Foundation, Inc. Contributed by Vladimir Makarov vmaka.nosp@m.rov@.nosp@m.redha.nosp@m.t.co.nosp@m.m.

This file is part of GCC.

GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.

GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/.

The flags is set up every time when we calculate pseudo register
   classes through function ira_set_pseudo_classes.   

Referenced by find_costs_and_classes(), and ira_set_pseudo_classes().

enum reg_class* regno_aclass
static
Record allocno class of each allocno with the same regno.   

Referenced by find_costs_and_classes(), finish_costs(), init_costs(), and setup_allocno_class_and_costs().

cost_classes_t* regno_cost_classes
static
Info about cost classes for each pseudo.   
int* regno_equiv_gains
static
Record cost gains for not allocating a register with an invariant
   equivalence.   

Referenced by find_costs_and_classes(), finish_costs(), init_costs(), and ira_adjust_equiv_reg_cost().

int struct_costs_size
static
It is the current size of struct costs.   

Referenced by find_costs_and_classes(), record_operand_costs(), and record_reg_classes().

struct costs* total_allocno_costs
static
Accumulated costs of each class for each allocno.