fixed indents
[libfirm] / ir / be / beconstrperm.c
1 /**
2  * Author:      Daniel Grund
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 walker_insert_constr_perms(ir_node *bl, void *env) {
23         ir_node *irn;
24         be_chordal_env_t *cenv = env;
25         const be_main_env_t *menv = cenv->main_env;
26         const arch_env_t *aenv = menv->arch_env;
27         arch_register_req_t req;
28         int pos, max;
29
30         sched_foreach(bl, irn) {
31                 ir_node *perm = NULL;
32
33                 /* check for a restriction of the result (-1) or one of the operands (0..n) */
34                 max = get_irn_arity(irn);
35                 for(pos=-1; pos<max; ++pos) {
36                         arch_get_register_req(aenv, &req, irn, pos);
37                         /* if a restriction is found, insert a perm before the irn */
38                         if (cenv->cls == arch_get_irn_reg_class(aenv, irn, pos) && req.type == arch_register_req_type_limited) {
39
40                                 if(!perm)
41                                         perm = insert_Perm_after(menv, cenv->cls, cenv->dom_front, sched_prev(irn));
42
43                                 /*
44                                  * Turn an input constraint into an output constraint:
45                                  * The Proj of the Perm which corresponds to the input
46                                  * constraint will have the input constraint of the node
47                                  * as an output constraint
48                                  */
49                                 if(pos >= 0) {
50                                         ir_node *op = get_irn_n(irn, pos);
51
52                                         /*
53                                          * The operand must be a proj now, since a perm cut
54                                          * all live ranges.
55                                          */
56                                         assert(is_Proj(op));
57                                         be_set_Perm_out_req(perm, get_Proj_proj(op), &req);
58                                 }
59                         }
60                 }
61
62                 /*
63                  * If we inserted a perm,
64                  * we have to recompute liveness analysis since inserting
65                  * a Perm changes the liveness situation at the end
66                  * of the block.
67                  * (its needed by successive calls to insert_Perm_after)
68                  * Perhaps thinking about an online liveness analysis
69                  * would help.
70                  */
71                 if(perm)
72                         be_liveness(get_irn_irg(bl));
73         }
74 }
75
76 void be_insert_constr_perms(be_chordal_env_t *cenv) {
77         irg_block_walk_graph(cenv->irg, walker_insert_constr_perms, NULL, cenv);
78 }