4 * Copyright: (c) Universitaet Karlsruhe
5 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
7 * Internal header for copy optimization problem.
10 #ifndef _BECOPYOPT_T_H
11 #define _BECOPYOPT_T_H
15 #include "bechordal_t.h"
16 #include "becopyopt.h"
18 #define MIS_HEUR_TRIGGER 8
21 * Data representing the problem of copy minimization.
24 be_chordal_env_t *cenv;
25 const arch_register_class_t *cls;
26 const arch_env_t *aenv;
28 char *name; /**< ProgName__IrgName__RegClassName */
30 struct list_head units; /**< all units to optimize in specific order */
31 cost_fct_t get_costs; /**< function ptr used to get costs for copies */
36 * A single unit of optimization. Lots of these form a copy-opt problem
38 typedef struct _unit_t {
39 struct list_head units; /**< chain for all units */
40 copy_opt_t *co; /**< the copy_opt this unit belongs to */
41 int node_count; /**< size of the nodes array */
42 ir_node **nodes; /**< [0] is the root-node, others are non interfering args of it. */
43 int *costs; /**< costs[i] are incurred, if nodes[i] has a different color */
44 int inevitable_costs; /**< sum of costs of all args interfering with root */
45 int all_nodes_costs; /**< sum of all costs[i] */
46 int min_nodes_costs; /**< a lower bound for the costs in costs[], determined by a max indep. set */
47 int sort_key; /**< maximum costs. controls the order of ou's in the struct list_head units. */
50 struct list_head queue; /**< list of qn's sorted by weight of qn-mis */
54 #define get_irn_col(co, irn) arch_register_get_index(arch_get_irn_register((co)->aenv, irn))
55 #define set_irn_col(co, irn, col) arch_set_irn_register((co)->aenv, irn, arch_register_for_index((co)->cls, col))
56 #define is_curr_reg_class(co, irn) (arch_get_irn_reg_class((co)->aenv, irn, -1) == (co)->cls)
58 #define MIN(a,b) ((a<b)?(a):(b))
59 #define MAX(a,b) ((a<b)?(b):(a))
61 #define list_entry_units(lh) list_entry(lh, unit_t, units)
63 #define get_Copy_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
64 #define is_Perm(arch_env, irn) (arch_irn_classify(arch_env, irn) == arch_irn_class_perm)
65 #define is_Reg_Phi(irn) (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
66 #define is_Perm_Proj(arch_env, irn) (is_Proj(irn) && is_Perm(arch_env, get_Proj_pred(irn)))
67 #define is_2addr_code(arch_env, irn, req) (arch_get_register_req(arch_env, req, irn, -1)->type == arch_register_req_type_should_be_same)
70 * Checks if a node is optimizable, viz. has somthing to do with coalescing
71 * @param arch The architecture environment
72 * @param irn The irn to check
73 * @param req A register_requirement structure (used to check for 2-addr-code)
75 #define co_is_optimizable(arch, irn, req) (!arch_irn_is_ignore(arch, irn) && (is_Reg_Phi(irn) || is_Perm_Proj(arch, irn) || is_2addr_code(arch, irn, req)))
78 * Checks if the irn is a non-interfering argument of a node which 'is_optimizable'
80 int co_is_optimizable_arg(const copy_opt_t *co, ir_node *irn);
83 * Returns the maximal costs possible, i.e. the costs if all
84 * pairs would be assigned different registers.
86 int co_get_max_copy_costs(const copy_opt_t *co);
89 * Returns the inevitable costs, i.e. the costs of
90 * all copy pairs which interfere.
92 int co_get_inevit_copy_costs(const copy_opt_t *co);
95 * Returns the current costs the copies are causing.
96 * The result includes inevitable costs and the costs
97 * of the copies regarding the current register allocation
99 int co_get_copy_costs(const copy_opt_t *co);
102 * Returns a lower bound for the costs of copies in this ou.
103 * The result includes inevitable costs and the costs of a
104 * minimal costs caused by the nodes of the ou.
106 int co_get_lower_bound(const copy_opt_t *co);