2 * This file is part of libFirm.
3 * Copyright (C) 2012 University of Karlsruhe.
8 * @brief Copy minimization driver.
12 * Main file for the optimization reducing the copies needed for:
14 * - Register-constrained nodes
15 * - Two-address code instructions
17 #ifndef FIRM_BE_BECOPYOPT_H
18 #define FIRM_BE_BECOPYOPT_H
22 #include "firm_types.h"
23 #include "bechordal.h"
25 typedef int(*cost_fct_t)(const ir_node *node, int input);
28 int (*copyopt)(copy_opt_t *co); /**< function ptr to run copyopt */
29 bool can_improve_existing;
33 * Register a new copy optimization algorithm.
35 * @param name the name of the copy optimazation algorithm,
37 * @param copyopt a copy optimazation entry
39 void be_register_copyopt(const char *name, co_algo_info *copyopt);
41 /** The driver for copy minimization. */
42 void co_driver(be_chordal_env_t *cenv);
45 * Generate the problem. Collect all information and optimizable nodes.
47 copy_opt_t *new_copy_opt(be_chordal_env_t *chordal_env, cost_fct_t get_costs);
50 * Free the space used...
52 void free_copy_opt(copy_opt_t *co);
55 * Statistics over a copy optimization module.
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;
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.
73 void co_complete_stats(const copy_opt_t *co, co_complete_stats_t *stat);
77 * Build internal optimization units structure
79 void co_build_ou_structure(copy_opt_t *co);
82 * Frees the space used by the opt unit representation.
83 * Does NOT free the whole copyopt structure
85 void co_free_ou_structure(copy_opt_t *co);
88 * Solves the problem using a heuristic approach
89 * Uses the OU data structure
91 int co_solve_heuristic(copy_opt_t *co);
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
98 int co_get_max_copy_costs(const copy_opt_t *co);
101 * Returns the inevitable costs, i.e. the costs of
102 * all copy pairs which interfere.
103 * Uses the OU data structure
105 int co_get_inevit_copy_costs(const copy_opt_t *co);
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
113 int co_get_copy_costs(const copy_opt_t *co);
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
121 int co_get_lower_bound(const copy_opt_t *co);
124 * Constructs another internal representation of the affinity edges
126 void co_build_graph_structure(copy_opt_t *co);
129 * Frees the space used by the graph representation.
130 * Does NOT free the whole copyopt structure
132 void co_free_graph_structure(copy_opt_t *co);
135 * Checks if a node is optimizable, viz has something to do with coalescing.
136 * Uses the GRAPH data structure
138 int co_gs_is_optimizable(copy_opt_t const *co, ir_node *irn);