becopyheur4: Clean up co_mst_irn_init().
[libfirm] / ir / be / becopyopt.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       Copy minimization driver.
9  * @author      Daniel Grund
10  * @date        11.04.2005
11  *
12  * Main file for the optimization reducing the copies needed for:
13  * - Phi coalescing
14  * - Register-constrained nodes
15  * - Two-address code instructions
16  */
17 #ifndef FIRM_BE_BECOPYOPT_H
18 #define FIRM_BE_BECOPYOPT_H
19
20 #include <stdbool.h>
21
22 #include "firm_types.h"
23 #include "bechordal.h"
24
25 typedef int(*cost_fct_t)(const ir_node *node, int input);
26
27 typedef struct {
28         int (*copyopt)(copy_opt_t *co); /**< function ptr to run copyopt */
29         bool can_improve_existing;
30 } co_algo_info;
31
32 /**
33  * Register a new copy optimization algorithm.
34  *
35  * @param name     the name of the copy optimazation algorithm,
36  *                 used to select it
37  * @param copyopt  a copy optimazation entry
38  */
39 void be_register_copyopt(const char *name, co_algo_info *copyopt);
40
41 /** The driver for copy minimization. */
42 void co_driver(be_chordal_env_t *cenv);
43
44 /**
45  * Generate the problem. Collect all information and optimizable nodes.
46  */
47 copy_opt_t *new_copy_opt(be_chordal_env_t *chordal_env, cost_fct_t get_costs);
48
49 /**
50  * Free the space used...
51  */
52 void free_copy_opt(copy_opt_t *co);
53
54 /**
55  * Statistics over a copy optimization module.
56  */
57 typedef struct {
58         unsigned long long aff_edges;            /**< number of affinity edges. */
59         unsigned long long aff_nodes;            /**< number of nodes with incident affinity edges. */
60         unsigned long long aff_int;              /**< number of affinity edges whose nodes also interfere. */
61         unsigned long long inevit_costs;         /**< costs which cannot be evited (due to interfering affinities). */
62         unsigned long long max_costs;            /**< all costs of the affinities. */
63         unsigned long long costs;                /**< The costs of the current coloring. */
64         unsigned long long unsatisfied_edges;    /**< The number of unequally colored affinity edges. */
65 } co_complete_stats_t;
66
67 /**
68  * Collect statistics of a copy optimization module.
69  * @param co    The copy optimization environment.
70  * @param stat  Where to put the stats.
71  * @note  This requires the graph info to be computed.
72  */
73 void co_complete_stats(const copy_opt_t *co, co_complete_stats_t *stat);
74
75
76 /**
77  * Build internal optimization units structure
78  */
79 void co_build_ou_structure(copy_opt_t *co);
80
81 /**
82  * Frees the space used by the opt unit representation.
83  * Does NOT free the whole copyopt structure
84  */
85 void co_free_ou_structure(copy_opt_t *co);
86
87 /**
88  * Solves the problem using a heuristic approach
89  * Uses the OU data structure
90  */
91 int co_solve_heuristic(copy_opt_t *co);
92
93 /**
94  * Returns the maximal costs possible, i.e. the costs if all
95  * pairs would be assigned different registers.
96  * Uses the OU data structure
97  */
98 int co_get_max_copy_costs(const copy_opt_t *co);
99
100 /**
101  * Returns the inevitable costs, i.e. the costs of
102  * all copy pairs which interfere.
103  * Uses the OU data structure
104  */
105 int co_get_inevit_copy_costs(const copy_opt_t *co);
106
107 /**
108  * Returns the current costs the copies are causing.
109  * The result includes inevitable costs and the costs
110  * of the copies regarding the current register allocation
111  * Uses the OU data structure
112  */
113 int co_get_copy_costs(const copy_opt_t *co);
114
115 /**
116  * Returns a lower bound for the costs of copies in this ou.
117  * The result includes inevitable costs and the costs of a
118  * minimal costs caused by the nodes of the ou.
119  * Uses the OU data structure
120  */
121 int co_get_lower_bound(const copy_opt_t *co);
122
123 /**
124  * Constructs another internal representation of the affinity edges
125  */
126 void co_build_graph_structure(copy_opt_t *co);
127
128 /**
129  * Frees the space used by the graph representation.
130  * Does NOT free the whole copyopt structure
131  */
132 void co_free_graph_structure(copy_opt_t *co);
133
134 /**
135  * Checks if a node is optimizable, viz has something to do with coalescing.
136  * Uses the GRAPH data structure
137  */
138 int co_gs_is_optimizable(copy_opt_t const *co, ir_node *irn);
139
140 #endif