becopyilp: Use a ir_nodeset instead of a pset for all_removed.
[libfirm] / ir / be / becopyilp_t.h
1 /*
2  * This file is part of libFirm.
3  * Copyright (C) 2012 University of Karlsruhe.
4  */
5
6 /**
7  * @file
8  * @brief       Common stuff used by all ILP formulations.
9  * @author      Daniel Grund
10  * @date        28.02.2006
11  */
12 #ifndef FIRM_BE_BECOPYILP_T_H
13 #define FIRM_BE_BECOPYILP_T_H
14
15 #include "firm_types.h"
16 #include "becopyopt_t.h"
17
18 /******************************************************************************
19     _____ _                        _            _   _
20    / ____(_)                      | |          | | (_)
21   | (___  _ _______   _ __ ___  __| |_   _  ___| |_ _  ___  _ __
22    \___ \| |_  / _ \ | '__/ _ \/ _` | | | |/ __| __| |/ _ \| '_ \
23    ____) | |/ /  __/ | | |  __/ (_| | |_| | (__| |_| | (_) | | | |
24   |_____/|_/___\___| |_|  \___|\__,_|\__,_|\___|\__|_|\___/|_| |_|
25
26  *****************************************************************************/
27
28 typedef struct coloring_suffix_t coloring_suffix_t;
29
30 struct coloring_suffix_t {
31         coloring_suffix_t *next;
32         ir_node           *irn;
33 };
34
35 typedef struct size_red_t {
36         copy_opt_t        *co;
37         ir_nodeset_t       all_removed;   /**< All nodes removed during problem size reduction */
38         coloring_suffix_t *col_suff;      /**< Coloring suffix. Reverse would be a PEO prefix */
39         struct obstack    ob;
40 } size_red_t;
41
42 /**
43  * Checks if a node has already been removed
44  */
45 static inline bool sr_is_removed(size_red_t const *const sr, ir_node const *const irn)
46 {
47         return ir_nodeset_contains(&sr->all_removed, irn);
48 }
49
50 /**
51  * TODO: This search is necessary because during the construction of the
52  *       units (ou's) args could be merged and weights are accumulated.
53  *       Is this necessary?
54  */
55 static inline int co_ilp_get_costs(copy_opt_t *co, ir_node *root, ir_node *arg) {
56         int i;
57
58         /* search optimization unit for phi */
59         list_for_each_entry(unit_t, curr, &co->units, units)
60                 if (curr->nodes[0] == root) {
61
62                         for (i = 1; i < curr->node_count; ++i)
63                                 if (curr->nodes[i] == arg)
64                                         return curr->costs[i];
65
66                                 assert(0 && "irn must occur in this ou");
67                 }
68
69         assert(0 && "phi must be found in a ou");
70         return 0;
71 }
72
73 /******************************************************************************
74     _____                      _        _____ _      _____
75    / ____|                    (_)      |_   _| |    |  __ \
76   | |  __  ___ _ __   ___ _ __ _  ___    | | | |    | |__) |
77   | | |_ |/ _ \ '_ \ / _ \ '__| |/ __|   | | | |    |  ___/
78   | |__| |  __/ | | |  __/ |  | | (__   _| |_| |____| |
79    \_____|\___|_| |_|\___|_|  |_|\___| |_____|______|_|
80
81  *****************************************************************************/
82
83 #include "lpp.h"
84 #include "lpp_net.h"
85
86 #define EPSILON 0.00001
87
88 typedef struct ilp_env_t ilp_env_t;
89
90 typedef void(*ilp_callback)(ilp_env_t*);
91
92 struct ilp_env_t {
93         const copy_opt_t *co;   /**< the copy opt problem */
94         size_red_t       *sr;   /**< problem size reduction. removes simple nodes */
95         lpp_t            *lp;   /**< the linear programming problem */
96         void             *env;
97         ilp_callback     build;
98         ilp_callback     apply;
99 };
100
101 ilp_env_t *new_ilp_env(copy_opt_t *co, ilp_callback build, ilp_callback apply, void *env);
102
103 lpp_sol_state_t ilp_go(ilp_env_t *ienv);
104
105 void free_ilp_env(ilp_env_t *ienv);
106
107 #endif