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 ASSERT_OU_AVAIL(co) assert((co)->units.next && "Representation as optimization-units not build")
40 #define ASSERT_GS_AVAIL(co) assert((co)->nodes && "Representation as graph not build")
42 #define get_irn_col(co, irn) arch_register_get_index(arch_get_irn_register((co)->aenv, irn))
43 #define set_irn_col(co, irn, col) arch_set_irn_register((co)->aenv, irn, arch_register_for_index((co)->cls, col))
44 #define is_curr_reg_class(co, irn) (arch_get_irn_reg_class((co)->aenv, irn, -1) == (co)->cls)
46 #define MIN(a,b) ((a<b)?(a):(b))
47 #define MAX(a,b) ((a<b)?(b):(a))
49 #define list_entry_units(lh) list_entry(lh, unit_t, units)
51 #define is_Reg_Phi(irn) (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
53 #define get_Perm_src(irn) (get_irn_n(get_Proj_pred(irn), get_Proj_proj(irn)))
54 #define is_Perm(arch_env, irn) (arch_irn_classify(arch_env, irn) == arch_irn_class_perm)
55 #define is_Perm_Proj(arch_env, irn) (is_Proj(irn) && is_Perm(arch_env, get_Proj_pred(irn)))
57 #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)
60 /******************************************************************************
61 ____ _ _ _ _ _ _____ _
62 / __ \ | | | | | | (_) | / ____| |
63 | | | |_ __ | |_| | | |_ __ _| |_ ___ | (___ | |_ ___ _ __ __ _ __ _ ___
64 | | | | '_ \| __| | | | '_ \| | __/ __| \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
65 | |__| | |_) | |_| |__| | | | | | |_\__ \ ____) | || (_) | | | (_| | (_| | __/
66 \____/| .__/ \__|\____/|_| |_|_|\__|___/ |_____/ \__\___/|_| \__,_|\__, |\___|
69 ******************************************************************************/
71 #define MIS_HEUR_TRIGGER 8
73 typedef struct _unit_t {
74 struct list_head units; /**< chain for all units */
75 copy_opt_t *co; /**< the copy opt this unit belongs to */
76 int node_count; /**< size of the nodes array */
77 ir_node **nodes; /**< [0] is the root-node, others are non interfering args of it. */
78 int *costs; /**< costs[i] are incurred, if nodes[i] has a different color */
79 int inevitable_costs; /**< sum of costs of all args interfering with root */
80 int all_nodes_costs; /**< sum of all costs[i] */
81 int min_nodes_costs; /**< a lower bound for the costs in costs[], determined by a max independent set */
82 int sort_key; /**< maximum costs. controls the order of ou's in the struct list_head units. */
85 struct list_head queue; /**< list of qn's sorted by weight of qn-mis */
90 /******************************************************************************
93 | | __ _ __ __ _ _ __ | |__ | (___ | |_ ___ _ __ __ _ __ _ ___
94 | | |_ | '__/ _` | '_ \| '_ \ \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
95 | |__| | | | (_| | |_) | | | | ____) | || (_) | | | (_| | (_| | __/
96 \_____|_| \__,_| .__/|_| |_| |_____/ \__\___/|_| \__,_|\__, |\___|
99 ******************************************************************************/
101 typedef struct _neighb_t neighb_t;
102 typedef struct _affinity_node_t affinity_node_t;
106 neighb_t *next; /** the next neighbour entry*/
107 ir_node *irn; /** the neighbour itself */
108 int costs; /** the costs of the edge (affinity_node_t->irn, neighb_t->irn) */
111 struct _affinity_node_t {
112 ir_node *irn; /** a node with affinity edges */
113 int degree; /** number of affinity edges in the linked list below */
114 neighb_t *neighbours; /** a linked list of all affinity neighbours */
118 static INLINE affinity_node_t *get_affinity_info(const copy_opt_t *co, ir_node *irn) {
119 affinity_node_t find;
124 return set_find(co->nodes, &find, sizeof(find), HASH_PTR(irn));
127 #define co_gs_nodes_begin(co) set_first((co)->nodes)
128 #define co_gs_nodes_next(co) set_next((co)->nodes)
129 #define co_gs_nodes_break(co) set_break((co)->nodes)
130 #define co_gs_foreach_aff_node(co, aff_node) for (aff_node = co_gs_nodes_begin(co); aff_node; aff_node = co_gs_nodes_next(co))
132 #define co_gs_foreach_neighb(aff_node, neighb) for (neighb = aff_node->neighbours; neighb; neighb = neighb->next)