5e3d4b3e1782916e7370e0893f82b294246a436f
[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
9 #include "irgraph_t.h"
10 #include "irnode_t.h"
11 #include "irgwalk.h"
12
13 #include "bearch.h"
14 #include "benode_t.h"
15 #include "besched_t.h"
16 #include "beconstrperm.h"
17
18 static void walker_insert_constr_perms(ir_node *irn, void *env) {
19         be_chordal_env_t *cenv = env;
20         const be_main_env_t *menv = cenv->main_env;
21         const arch_env_t *aenv = menv->arch_env;
22         arch_register_req_t req;
23         int pos, max;
24
25         /* check for a restriction of the result (-1) and the operands (0..n) */
26         max = get_irn_arity(irn);
27         for(pos=-1; pos<max; ++pos) {
28                 arch_get_register_req(aenv, &req, irn, pos);
29                 /* if a restriction is found, insert a perm before the irn */
30                 if (req.type == arch_register_req_type_limited) {
31                         insert_Perm_after(menv, cenv->cls, cenv->dom_front, sched_prev(irn));
32                         break;
33                 }
34         }
35 }
36
37 void be_insert_constr_perms(be_chordal_env_t *cenv) {
38         irg_walk_graph(cenv->irg, walker_insert_constr_perms, NULL, cenv);
39 }