4 * Copyright: (c) Universitaet Karlsruhe
5 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
7 * Header for copy optimization problem. Analysis and set up of the problem.
29 #include "bechordal_t.h"
32 #define DEBUG_IRG "!!deflate.c__longest_match__datab"
33 #define DEBUG_IRG_LVL_CO SET_LEVEL_1
34 #define DEBUG_IRG_LVL_HEUR SET_LEVEL_1
35 #define DEBUG_IRG_LVL_ILP SET_LEVEL_1
36 #define DEBUG_LVL_CO SET_LEVEL_0
37 #define DEBUG_LVL_HEUR SET_LEVEL_0
38 #define DEBUG_LVL_ILP SET_LEVEL_0
40 #define MIS_HEUR_TRIGGER 8
43 typedef int(*cost_fct_t)(ir_node*, ir_node*, int);
46 * Data representing the problem of copy minimization.
48 typedef struct _copy_opt_t {
49 be_chordal_env_t *chordal_env;
50 char *name; /**< ProgName__IrgName__RegClass */
51 struct list_head units; /**< all units to optimize in right order */
52 pset *roots; /**< used only temporary for detecting multiple appends */
53 cost_fct_t get_costs; /**< function ptr used to get costs for copies */
58 * A single unit of optimization. Lots of these form a copy-opt problem
60 typedef struct _unit_t {
61 struct list_head units; /**< chain for all units */
62 copy_opt_t *co; /**< the copy_opt this unit belongs to */
63 int node_count; /**< size of the nodes array */
64 ir_node **nodes; /**< [0] is the root-node, others are non interfering args of it. */
65 int *costs; /**< costs[i] are arising, if nodes[i] has a different color */
66 int inevitable_costs; /**< sum of costs of all args interfering with root */
67 int all_nodes_costs; /**< sum of all costs[i] */
68 int min_nodes_costs; /**< a lower bound for the costs in costs[], determined by a max indep. set */
69 int sort_key; /**< maximum costs. controls the order of ou's in the struct list_head units. */
72 struct list_head queue; /**< list of qn's sorted by weight of qn-mis */
76 #define get_arch_env(co) ((co)->chordal_env->main_env->arch_env)
77 #define get_irg(co) ((co)->chordal_env->irg)
78 #define get_irn_col(co, irn) \
79 arch_register_get_index(arch_get_irn_register(get_arch_env(co), irn))
80 #define set_irn_col(co, irn, col) \
81 arch_set_irn_register(get_arch_env(co), irn, arch_register_for_index(co->chordal_env->cls, col))
84 #define list_entry_units(lh) list_entry(lh, unit_t, units)
88 * Generate the problem. Collect all infos and optimizable nodes.
90 copy_opt_t *new_copy_opt(be_chordal_env_t *chordal_env, int (*get_costs)(ir_node*, ir_node*, int));
95 void free_copy_opt(copy_opt_t *co);
98 #define is_Perm(arch_env, irn) (arch_irn_classify(arch_env, irn) == arch_irn_class_perm)
101 * A copy is a proj haning out of perm node
103 #define is_Copy(arch_env, irn) (is_Proj(irn) && is_Perm(arch_env, get_Proj_pred(irn)))
106 * returns the corresponding argument of the perm node for a copy
108 #define get_Copy_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
111 * Checks if a node is optimizable, viz. is a target of a 'copy-op'
113 #define is_optimizable(arch_env, irn) ((is_Phi(irn) && is_firm_be_mode(get_irn_mode(irn))) || is_Copy(arch_env, irn))
116 * Checks if the irn is a non-interfering argument of a node which 'is_optimizable'
118 int is_optimizable_arg(const copy_opt_t *co, ir_node *irn);
121 * Computes the costs of a copy according to loop depth
122 * @param root, arg: clear.
123 * @param pos: -1 for perm-copies.
124 * Else the argument position of arg in the phi node root.
125 * @return Must be >= 0 in all cases.
127 int get_costs_loop_depth(ir_node *root, ir_node* arg, int pos);
130 * All costs equal 1. Using this will reduce the number of copies.
131 * @return Must be >= 0 in all cases.
133 int get_costs_all_one(ir_node *root, ir_node* arg, int pos);
136 * Returns the maximal costs possible, i.e. the costs if all
137 * pairs would be assigned different registers.
139 int co_get_max_copy_costs(const copy_opt_t *co);
142 * Returns the inevitable costs, i.e. the costs of
143 * all copy pairs which interfere.
145 int co_get_inevit_copy_costs(const copy_opt_t *co);
148 * Returns the current costs the copies are causing.
149 * The result includes inevitable costs and the costs
150 * of the copies regarding the current register allocation
152 int co_get_copy_costs(const copy_opt_t *co);
155 * Returns a lower bound for the costs of copies in this ou.
156 * The result includes inevitable costs and the costs of a
157 * minimal costs caused by the nodes of the ou.
159 int co_get_lower_bound(const copy_opt_t *co);
162 * Solves the problem using a heuristic approach
164 void co_heur_opt(copy_opt_t *co);
167 * Solves the problem using mixed integer programming
168 * @returns 1 iff solution state was optimal
170 int co_ilp_opt(copy_opt_t *co, double time_limit);