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