unified mein file comments
[libfirm] / ir / be / beinsn.c
1 /*
2  * Copyright (C) 1995-2007 University of Karlsruhe.  All right reserved.
3  *
4  * This file is part of libFirm.
5  *
6  * This file may be distributed and/or modified under the terms of the
7  * GNU General Public License version 2 as published by the Free Software
8  * Foundation and appearing in the file LICENSE.GPL included in the
9  * packaging of this file.
10  *
11  * Licensees holding valid libFirm Professional Edition licenses may use
12  * this file in accordance with the libFirm Commercial License.
13  * Agreement provided with the Software.
14  *
15  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17  * PURPOSE.
18  */
19
20 /**
21  * @file
22  * @brief       A data structure to treat nodes and node-proj collections uniformly.
23  * @author      Sebastian Hack
24  * @version     $Id$
25  */
26 #ifdef HAVE_CONFIG_H
27 #include "config.h"
28 #endif
29
30 #include "irgraph_t.h"
31 #include "irmode_t.h"
32 #include "irnode_t.h"
33
34 #include "besched_t.h"
35 #include "beinsn_t.h"
36 #include "beirg_t.h"
37 #include "beabi.h"
38 #include "raw_bitset.h"
39
40 be_insn_t *be_scan_insn(const be_insn_env_t *env, ir_node *irn)
41 {
42         const arch_env_t *arch_env = env->aenv;
43         struct obstack *obst       = env->obst;
44         be_operand_t o;
45         be_insn_t *insn;
46         int i, n;
47         int pre_colored = 0;
48
49         insn = obstack_alloc(obst, sizeof(insn[0]));
50         memset(insn, 0, sizeof(insn[0]));
51
52         insn->irn       = irn;
53         insn->next_insn = sched_next(irn);
54         if(get_irn_mode(irn) == mode_T) {
55                 ir_node *p;
56
57                 for(p = sched_next(irn); is_Proj(p); p = sched_next(p)) {
58                         if(arch_irn_consider_in_reg_alloc(arch_env, env->cls, p)) {
59                                 o.req             = arch_get_register_req(arch_env, p, -1);
60                                 o.carrier         = p;
61                                 o.irn             = irn;
62                                 o.pos             = -(get_Proj_proj(p) + 1);
63                                 o.partner         = NULL;
64                                 o.has_constraints = arch_register_req_is(o.req, limited);
65                                 obstack_grow(obst, &o, sizeof(o));
66                                 insn->n_ops++;
67                                 insn->out_constraints |= o.has_constraints;
68                                 pre_colored += arch_get_irn_register(arch_env, p) != NULL;
69                         }
70                 }
71
72                 insn->next_insn = p;
73         } else if(arch_irn_consider_in_reg_alloc(arch_env, env->cls, irn)) {
74                 o.req     = arch_get_register_req(arch_env, irn, -1);
75                 o.carrier = irn;
76                 o.irn     = irn;
77                 o.pos     = -1;
78                 o.partner = NULL;
79                 o.has_constraints = arch_register_req_is(o.req, limited);
80                 obstack_grow(obst, &o, sizeof(o));
81                 insn->n_ops++;
82                 insn->out_constraints |= o.has_constraints;
83                 pre_colored += arch_get_irn_register(arch_env, irn) != NULL;
84         }
85
86         if(pre_colored > 0) {
87                 assert(pre_colored == insn->n_ops && "partly pre-colored nodes not supported");
88                 insn->pre_colored = 1;
89         }
90         insn->use_start   = insn->n_ops;
91
92         for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
93                 ir_node *op = get_irn_n(irn, i);
94
95                 if(!arch_irn_consider_in_reg_alloc(arch_env, env->cls, op))
96                         continue;
97
98                 o.req     = arch_get_register_req(arch_env, irn, i);
99                 o.carrier = op;
100                 o.irn     = irn;
101                 o.pos     = i;
102                 o.partner = NULL;
103                 o.has_constraints = arch_register_req_is(o.req, limited);
104                 obstack_grow(obst, &o, sizeof(o));
105                 insn->n_ops++;
106                 insn->in_constraints |= o.has_constraints;
107         }
108
109         insn->has_constraints = insn->in_constraints | insn->out_constraints;
110         insn->ops = obstack_finish(obst);
111
112         /* Compute the admissible registers bitsets. */
113         for (i = 0; i < insn->n_ops; ++i) {
114                 be_operand_t *op = &insn->ops[i];
115                 const arch_register_req_t   *req = op->req;
116                 const arch_register_class_t *cls = req->cls;
117                 arch_register_req_type_t    type = req->type;
118
119                 /* If there is no special requirement, we allow current class here */
120                 if (cls == NULL && req->type == arch_register_req_type_none) {
121                         cls  = env->cls;
122                         type = arch_register_req_type_normal;
123                 }
124
125                 assert(cls == env->cls);
126
127                 op->regs = bitset_obstack_alloc(obst, env->cls->n_regs);
128
129                 if (type & arch_register_req_type_limited) {
130                         rbitset_copy_to_bitset(req->limited, op->regs);
131                 } else {
132                         arch_put_non_ignore_regs(arch_env, env->cls, op->regs);
133                         if (env->ignore_colors)
134                                 bitset_andnot(op->regs, env->ignore_colors);
135                 }
136         }
137
138         return insn;
139 }
140
141 be_insn_env_t *be_insn_env_init(be_insn_env_t *ie, const be_irg_t *birg,
142                                 const arch_register_class_t *cls,
143                                 struct obstack *obst)
144 {
145         ie->aenv = be_get_birg_arch_env(birg);
146         ie->cls  = cls;
147         ie->obst = obst;
148         ie->ignore_colors = bitset_obstack_alloc(obst, cls->n_regs);
149         be_abi_put_ignore_regs(birg->abi, cls, ie->ignore_colors);
150
151         return ie;
152 }