4 * Copyright: (c) Universitaet Karlsruhe
5 * Licence: This file protected by GPL - GNU GENERAL PUBLIC LICENSE.
7 * Header for copy optimization problem. Analysis and set up of the problem.
19 #include "sp_matrix.h"
30 #include "bechordal_t.h"
34 #define is_Copy(irn) 0
35 #define DEBUG_IRG "-scanner.c__init_td__gp"
38 * Data representing the problem of copy minimization.
40 typedef struct _copy_opt_t {
41 be_chordal_env_t *chordal_env;
42 ir_graph *irg; /**< the irg to process */
43 char *name; /**< ProgName__IrgName__RegClass */
44 const arch_env_t *env; /**< Environment (isa + handlers) */
45 const arch_register_class_t *cls; /**< the registerclass all nodes belong to (in this pass) */
46 struct list_head units; /**< all units to optimize in right order */
47 pset *roots; /**< used only temporary for detecting multiple appends */
52 * A single unit of optimization. Lots of these form a copy-opt problem
54 typedef struct _unit_t {
55 struct list_head units; /**< chain for all units */
56 copy_opt_t *co; /**< the copy_opt this unit belongs to */
57 int interf; /**< number of nodes dropped due to interference */
58 int node_count; /**< size of the nodes array */
59 ir_node **nodes; /**< [0] is the root-node, others are non interfering args of it. */
62 int mis_size; /**< size of a mis considering only ifg (not coloring conflicts) */
63 struct list_head queue; /**< list of (mis/color) sorted by size of mis */
67 #define set_irn_col(co, irn, col) \
68 arch_set_irn_register(co->env, irn, 0, arch_register_for_index(co->cls, col))
70 #define get_irn_col(co, irn) \
71 arch_register_get_index(arch_get_irn_register(co->env, irn, 0))
75 * Generate the problem. Collect all infos and optimizable nodes.
77 copy_opt_t *new_copy_opt(be_chordal_env_t *chordal_env,
78 const arch_env_t *env, const arch_register_class_t *cls);
83 void free_copy_opt(copy_opt_t *co);
85 #define is_optimizable(irn) (is_Phi(irn) || is_Copy(irn))
88 * Checks if the irn is a non-interfering argument of a node which 'is_optimizable'
90 int is_optimizable_arg(const copy_opt_t *co, ir_node *irn);
93 * Returns the current number of copies needed
95 int co_get_copy_count(const copy_opt_t *co);
98 * IMPORTANT: Available only iff heuristic has run!
99 * Returns a lower bound for the number of copies needed based on interfering
100 * arguments and the size of a max indep. set (only ifg-edges) of the other args.
102 int co_get_lower_bound(const copy_opt_t *co);
105 * Returns the number of arguments interfering with their root node. This also
106 * is a (worse) lower bound for the number of copies needed.
108 int co_get_interferer_count(const copy_opt_t *co);
111 * Solves the problem using a heuristic approach
113 void co_heur_opt(copy_opt_t *co);
116 * Solves the problem using mixed integer programming
118 void co_ilp_opt(copy_opt_t *co);
121 * Checks the register allocation for correctness
123 void co_check_allocation(copy_opt_t *co);