fixed some minor bugs
[libfirm] / ir / be / becopyopt_t.h
1 /**
2  * Author:      Daniel Grund
3  * Date:                12.04.2005
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  *
7  * Internal header for copy optimization problem.
8  */
9
10 #ifndef _BECOPYOPT_T_H
11 #define _BECOPYOPT_T_H
12
13 #include <obstack.h>
14 #include "list.h"
15 #include "bearch.h"
16 #include "bechordal_t.h"
17 #include "becopyopt.h"
18
19 /**
20  * Data representing the problem of copy minimization.
21  */
22 struct _copy_opt_t {
23         be_chordal_env_t *cenv;
24         const arch_register_class_t *cls;
25         const arch_env_t *aenv;
26         ir_graph *irg;
27         char *name;                                             /**< ProgName__IrgName__RegClassName */
28         cost_fct_t get_costs;                   /**< function ptr used to get costs for copies */
29
30         /** Representation as optimization units */
31         struct list_head units;                 /**< all units to optimize in specific order */
32
33         /** Representation in graph structure. Only build on demand */
34         struct obstack obst;
35         set *nodes;
36 };
37
38 /* Helpers */
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)
42
43 #define MIN(a,b) ((a<b)?(a):(b))
44 #define MAX(a,b) ((a<b)?(b):(a))
45
46 #define list_entry_units(lh) list_entry(lh, unit_t, units)
47
48 #define is_Reg_Phi(irn)                                         (is_Phi(irn) && mode_is_data(get_irn_mode(irn)))
49
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)))
53
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)
55
56
57 /******************************************************************************
58    ____        _   _    _       _ _          _____ _
59   / __ \      | | | |  | |     (_) |        / ____| |
60  | |  | |_ __ | |_| |  | |_ __  _| |_ ___  | (___ | |_ ___  _ __ __ _  __ _  ___
61  | |  | | '_ \| __| |  | | '_ \| | __/ __|  \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
62  | |__| | |_) | |_| |__| | | | | | |_\__ \  ____) | || (_) | | | (_| | (_| |  __/
63   \____/| .__/ \__|\____/|_| |_|_|\__|___/ |_____/ \__\___/|_|  \__,_|\__, |\___|
64         | |                                                            __/ |
65         |_|                                                           |___/
66  ******************************************************************************/
67
68 #define MIS_HEUR_TRIGGER 8
69
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. */
80
81         /* for heuristic */
82         struct list_head queue;         /**< list of qn's sorted by weight of qn-mis */
83 } unit_t;
84
85
86
87 /******************************************************************************
88    _____                 _        _____ _
89   / ____|               | |      / ____| |
90  | |  __ _ __ __ _ _ __ | |__   | (___ | |_ ___  _ __ __ _  __ _  ___
91  | | |_ | '__/ _` | '_ \| '_ \   \___ \| __/ _ \| '__/ _` |/ _` |/ _ \
92  | |__| | | | (_| | |_) | | | |  ____) | || (_) | | | (_| | (_| |  __/
93   \_____|_|  \__,_| .__/|_| |_| |_____/ \__\___/|_|  \__,_|\__, |\___|
94                   | |                                       __/ |
95                   |_|                                      |___/
96  ******************************************************************************/
97
98 typedef struct _neighb_t neighb_t;
99 typedef struct _node_t node_t;
100
101
102 struct _neighb_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) */
106 };
107
108 struct _node_t {
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 */
112 };
113
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))
118
119 #define co_gs_foreach_neighb(node, neighb)      for (neighb = node->neighbours; neighb; neighb = neighb->next)
120
121 #endif