bugfix (check for register class)
[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                 /* check for a restriction of the result (-1) or one of the operands (0..n) */
32                 max = get_irn_arity(irn);
33                 for(pos=-1; pos<max; ++pos) {
34                         arch_get_register_req(aenv, &req, irn, pos);
35                         /* if a restriction is found, insert a perm before the irn */
36                         if (cenv->cls == arch_get_irn_reg_class(aenv, irn, pos) && req.type == arch_register_req_type_limited) {
37                                 insert_Perm_after(menv, cenv->cls, cenv->dom_front, sched_prev(irn));
38                                 /* TODO: Next line is overkill. Update_liveness would suffice. */
39                                 be_liveness(get_irn_irg(bl));
40                                 break;
41                         }
42                 }
43         }
44 }
45
46 void be_insert_constr_perms(be_chordal_env_t *cenv) {
47         irg_block_walk_graph(cenv->irg, walker_insert_constr_perms, NULL, cenv);
48 }