adapted to changes
[libfirm] / ir / be / beconstrperm.c
1 /**
2  * Author:      Daniel Grund, Sebastian Hack
3  * Date:                15.12.2005
4  * Copyright:   (c) Universitaet Karlsruhe
5  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
6  *
7  */
8 #ifdef HAVE_CONFIG_H
9 #include "config.h"
10 #endif
11
12 #include "irgraph_t.h"
13 #include "irnode_t.h"
14 #include "irgwalk.h"
15
16 #include "bearch.h"
17 #include "belive_t.h"
18 #include "benode_t.h"
19 #include "besched_t.h"
20 #include "beconstrperm.h"
21
22 static void check_constraints(const be_chordal_env_t *cenv, ir_node *base, ir_node *irn, ir_node **perm)
23 {
24         const arch_env_t *aenv    = cenv->main_env->arch_env;
25         const be_main_env_t *menv = cenv->main_env;
26         arch_register_req_t req;
27         int pos, n;
28
29         assert(is_Proj(irn) || (base == irn));
30
31         for(pos = -1, n = get_irn_arity(irn); pos < n; ++pos) {
32                 arch_get_register_req(aenv, &req, irn, pos);
33
34                 if(arch_irn_has_reg_class(aenv, irn, pos, cenv->cls)
35                         && arch_register_req_is(&req, limited)
36                         && !arch_irn_is_ignore(aenv, irn)) {
37
38                 /*
39                 * If we inserted a perm,
40                 * we have to recompute liveness analysis since inserting
41                 * a Perm changes the liveness situation at the end
42                 * of the block.
43                 * (its needed by successive calls to insert_Perm_after)
44                 * Perhaps thinking about an online liveness analysis
45                 * would help.
46                         */
47                         if(*perm == NULL) {
48                                 *perm = insert_Perm_after(aenv, cenv->cls, cenv->dom_front, sched_prev(base));
49                                 be_liveness(cenv->irg);
50                         }
51
52                         /*
53                         * Turn an input constraint into an output constraint:
54                         * The Proj of the Perm which corresponds to the input
55                         * constraint will have the input constraint of the node
56                         * as an output constraint
57                         */
58                         if(pos >= 0) {
59                                 ir_node *op = get_irn_n(irn, pos);
60
61                                 /*
62                                 * The operand must be a proj now, since a perm cut
63                                 * all live ranges.
64                                 */
65                                 assert(is_Proj(op));
66                                 be_set_Perm_out_req(*perm, get_Proj_proj(op), &req);
67                         }
68                 }
69         }
70 }
71
72 static void walker_insert_constr_perms(ir_node *bl, void *env) {
73         be_chordal_env_t *cenv    = env;
74         ir_node *irn;
75
76         for(irn = sched_first(bl); !sched_is_end(irn); irn = sched_next(irn)) {
77                 ir_node *perm = NULL;
78
79                 if(get_irn_mode(irn) == mode_T) {
80                         ir_node *proj;
81
82                         for(proj = sched_next(irn); is_Proj(proj); proj = sched_next(proj))
83                                 check_constraints(cenv, irn, proj, &perm);
84
85                         irn = sched_prev(proj);
86                 }
87
88                 else
89                         check_constraints(cenv, irn, irn, &perm);
90         }
91 }
92
93 void be_insert_constr_perms(be_chordal_env_t *cenv) {
94         irg_block_walk_graph(cenv->irg, walker_insert_constr_perms, NULL, cenv);
95 }