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 MIS_HEUR_TRIGGER 8
34 typedef int(*cost_fct_t)(ir_node*, ir_node*, int);
37 * Data representing the problem of copy minimization.
39 typedef struct _copy_opt_t {
40 be_chordal_env_t *chordal_env;
41 char *name; /**< ProgName__IrgName__RegClass */
42 struct list_head units; /**< all units to optimize in specific order */
43 cost_fct_t get_costs; /**< function ptr used to get costs for copies */
48 * A single unit of optimization. Lots of these form a copy-opt problem
50 typedef struct _unit_t {
51 struct list_head units; /**< chain for all units */
52 copy_opt_t *co; /**< the copy_opt this unit belongs to */
53 int node_count; /**< size of the nodes array */
54 ir_node **nodes; /**< [0] is the root-node, others are non interfering args of it. */
55 int *costs; /**< costs[i] are arising, if nodes[i] has a different color */
56 int inevitable_costs; /**< sum of costs of all args interfering with root */
57 int all_nodes_costs; /**< sum of all costs[i] */
58 int min_nodes_costs; /**< a lower bound for the costs in costs[], determined by a max indep. set */
59 int sort_key; /**< maximum costs. controls the order of ou's in the struct list_head units. */
62 struct list_head queue; /**< list of qn's sorted by weight of qn-mis */
66 #define get_arch_env(co) ((co)->chordal_env->main_env->arch_env)
67 #define get_irg(co) ((co)->chordal_env->irg)
68 #define get_irn_col(co, irn) \
69 arch_register_get_index(arch_get_irn_register(get_arch_env(co), irn))
70 #define set_irn_col(co, irn, col) \
71 arch_set_irn_register(get_arch_env(co), irn, arch_register_for_index(co->chordal_env->cls, col))
74 #define list_entry_units(lh) list_entry(lh, unit_t, units)
76 #define get_Copy_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
77 #define is_Perm(arch_env, irn) (arch_irn_classify(arch_env, irn) == arch_irn_class_perm)
78 #define is_Reg_Phi(irn) (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
79 #define is_Perm_Proj(arch_env, irn) (is_Proj(irn) && is_Perm(arch_env, get_Proj_pred(irn)))
80 #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)
84 * Generate the problem. Collect all infos and optimizable nodes.
86 copy_opt_t *new_copy_opt(be_chordal_env_t *chordal_env, int (*get_costs)(ir_node*, ir_node*, int));
91 void free_copy_opt(copy_opt_t *co);
94 * Checks if a node is optimizable, viz. has somthing to do with coalescing
95 * @param arch The architecture environment
96 * @param irn The irn to check
97 * @param req A register_requirement structure (used to check for 2-addr-code)
99 #define 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)))
102 * Checks if the irn is a non-interfering argument of a node which 'is_optimizable'
104 int is_optimizable_arg(const copy_opt_t *co, ir_node *irn);
107 * Computes the costs of a copy according to loop depth
108 * @param pos: the argument position of arg in the root arguments
109 * @return Must be >= 0 in all cases.
111 int get_costs_loop_depth(ir_node *root, ir_node* arg, int pos);
114 * All costs equal 1. Using this will reduce the number of copies.
115 * @return Must be >= 0 in all cases.
117 int get_costs_all_one(ir_node *root, ir_node* arg, int pos);
120 * Returns the maximal costs possible, i.e. the costs if all
121 * pairs would be assigned different registers.
123 int co_get_max_copy_costs(const copy_opt_t *co);
126 * Returns the inevitable costs, i.e. the costs of
127 * all copy pairs which interfere.
129 int co_get_inevit_copy_costs(const copy_opt_t *co);
132 * Returns the current costs the copies are causing.
133 * The result includes inevitable costs and the costs
134 * of the copies regarding the current register allocation
136 int co_get_copy_costs(const copy_opt_t *co);
139 * Returns a lower bound for the costs of copies in this ou.
140 * The result includes inevitable costs and the costs of a
141 * minimal costs caused by the nodes of the ou.
143 int co_get_lower_bound(const copy_opt_t *co);
146 * Solves the problem using a heuristic approach
148 void co_heur_opt(copy_opt_t *co);
151 * Solves the problem using mixed integer programming
152 * @returns 1 iff solution state was optimal
154 int co_ilp_opt(copy_opt_t *co, double time_limit);