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
16 #include "bechordal_t.h"
17 #include "becopyopt.h"
20 * Data representing the problem of copy minimization.
23 be_chordal_env_t *cenv;
24 const arch_register_class_t *cls;
25 const arch_env_t *aenv;
27 char *name; /**< ProgName__IrgName__RegClassName */
28 cost_fct_t get_costs; /**< function ptr used to get costs for copies */
30 /** Representation as optimization units */
31 struct list_head units; /**< all units to optimize in specific order */
33 /** Representation in graph structure. Only build on demand */
39 #define get_irn_col(co, irn) arch_register_get_index(arch_get_irn_register((co)->aenv, irn))
40 #define set_irn_col(co, irn, col) arch_set_irn_register((co)->aenv, irn, arch_register_for_index((co)->cls, col))
41 #define is_curr_reg_class(co, irn) (arch_get_irn_reg_class((co)->aenv, irn, -1) == (co)->cls)
43 #define MIN(a,b) ((a<b)?(a):(b))
44 #define MAX(a,b) ((a<b)?(b):(a))
46 #define list_entry_units(lh) list_entry(lh, unit_t, units)
48 #define is_Reg_Phi(irn) (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
50 #define get_Perm_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
51 #define is_Perm(arch_env, irn) (arch_irn_classify(arch_env, irn) == arch_irn_class_perm)
52 #define is_Perm_Proj(arch_env, irn) (is_Proj(irn) && is_Perm(arch_env, get_Proj_pred(irn)))
54 #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)
57 /******************************************************************************
58 ____ _ _ _ _ _ _____ _
59 / __ \ | | | | | | (_) | / ____| |
60 | | | |_ __ | |_| | | |_ __ _| |_ ___ | (___ | |_ ___ _ __ __ _ __ _ ___
61 | | | | '_ \| __| | | | '_ \| | __/ __| \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
62 | |__| | |_) | |_| |__| | | | | | |_\__ \ ____) | || (_) | | | (_| | (_| | __/
63 \____/| .__/ \__|\____/|_| |_|_|\__|___/ |_____/ \__\___/|_| \__,_|\__, |\___|
66 ******************************************************************************/
68 #define MIS_HEUR_TRIGGER 8
70 typedef struct _unit_t {
71 struct list_head units; /**< chain for all units */
72 copy_opt_t *co; /**< the copy opt this unit belongs to */
73 int node_count; /**< size of the nodes array */
74 ir_node **nodes; /**< [0] is the root-node, others are non interfering args of it. */
75 int *costs; /**< costs[i] are incurred, if nodes[i] has a different color */
76 int inevitable_costs; /**< sum of costs of all args interfering with root */
77 int all_nodes_costs; /**< sum of all costs[i] */
78 int min_nodes_costs; /**< a lower bound for the costs in costs[], determined by a max independent set */
79 int sort_key; /**< maximum costs. controls the order of ou's in the struct list_head units. */
82 struct list_head queue; /**< list of qn's sorted by weight of qn-mis */
87 /******************************************************************************
90 | | __ _ __ __ _ _ __ | |__ | (___ | |_ ___ _ __ __ _ __ _ ___
91 | | |_ | '__/ _` | '_ \| '_ \ \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
92 | |__| | | | (_| | |_) | | | | ____) | || (_) | | | (_| | (_| | __/
93 \_____|_| \__,_| .__/|_| |_| |_____/ \__\___/|_| \__,_|\__, |\___|
96 ******************************************************************************/
98 typedef struct _neighb_t neighb_t;
99 typedef struct _node_t node_t;
103 neighb_t *next; /** the next neighbour entry*/
104 ir_node *irn; /** the neighbour itself */
105 int costs; /** the costs of the edge (node_t->irn, neighb_t->irn) */
109 ir_node *irn; /** a node with affinity edges */
110 int count; /** number of affinity edges in the linked list below */
111 neighb_t *neighbours; /** a linked list of all affinity neighbours */
114 #define co_gs_nodes_begin(co) set_first((co)->nodes)
115 #define co_gs_nodes_next(co) set_next((co)->nodes)
116 #define co_gs_nodes_break(co) set_break((co)->nodes)
117 #define co_gs_foreach_node(co, node) for (node = co_gs_nodes_begin(co); node; node = co_gs_nodes_next(co))
119 #define co_gs_foreach_neighb(node, neighb) for (neighb = node->neighbours; neighb; neighb = neighb->next)