simplify splitting for double-width values
[libfirm] / ir / be / beinsn.c
1 /*
2  * Copyright (C) 1995-2008 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  */
25 #include "config.h"
26
27 #include "irgraph_t.h"
28 #include "irmode_t.h"
29 #include "irnode_t.h"
30 #include "iredges.h"
31
32 #include "besched.h"
33 #include "beinsn_t.h"
34 #include "beirg.h"
35 #include "beabi.h"
36 #include "raw_bitset.h"
37
38 /**
39  * Create a be_insn_t for an IR node.
40  *
41  * @param env      the insn construction environment
42  * @param irn      the irn for which the be_insn should be build
43  *
44  * @return the be_insn for the IR node
45  */
46 be_insn_t *be_scan_insn(const be_insn_env_t *env, ir_node *irn)
47 {
48         struct obstack *obst = env->obst;
49         be_operand_t o;
50         be_insn_t *insn;
51         int i, n;
52         int pre_colored = 0;
53
54         insn = OALLOCZ(obst, be_insn_t);
55
56         insn->irn       = irn;
57         insn->next_insn = sched_next(irn);
58         if (get_irn_mode(irn) == mode_T) {
59                 const ir_edge_t *edge;
60                 ir_node *p;
61
62                 /* This instruction might create more than one def. These are handled
63                    by Proj's, find them. */
64                 foreach_out_edge(irn, edge) {
65                         p = get_edge_src_irn(edge);
66
67                         /* did not work if the result is a ProjT. This should NOT happen
68                            in the backend, but check it for now. */
69                         assert(get_irn_mode(p) != mode_T);
70
71                         if (arch_irn_consider_in_reg_alloc(env->cls, p)) {
72                                 /* found a def: create a new operand */
73                                 o.req             = arch_get_irn_register_req(p);
74                                 o.carrier         = p;
75                                 o.irn             = irn;
76                                 o.pos             = -(get_Proj_proj(p) + 1);
77                                 o.partner         = NULL;
78                                 o.has_constraints = arch_register_req_is(o.req, limited) | (o.req->width > 1);
79                                 obstack_grow(obst, &o, sizeof(o));
80                                 insn->n_ops++;
81                                 insn->out_constraints |= o.has_constraints;
82                                 pre_colored += arch_get_irn_register(p) != NULL;
83                         }
84                 }
85         } else if (arch_irn_consider_in_reg_alloc(env->cls, irn)) {
86                 /* only one def, create one operand */
87                 o.req     = arch_get_irn_register_req(irn);
88                 o.carrier = irn;
89                 o.irn     = irn;
90                 o.pos     = -1;
91                 o.partner = NULL;
92                 o.has_constraints = arch_register_req_is(o.req, limited) | (o.req->width > 1);
93                 obstack_grow(obst, &o, sizeof(o));
94                 insn->n_ops++;
95                 insn->out_constraints |= o.has_constraints;
96                 pre_colored += arch_get_irn_register(irn) != NULL;
97         }
98
99         if (pre_colored > 0) {
100                 assert(pre_colored == insn->n_ops && "partly pre-colored nodes not supported");
101                 insn->pre_colored = 1;
102         }
103         insn->use_start   = insn->n_ops;
104
105         /* now collect the uses for this node */
106         for (i = 0, n = get_irn_arity(irn); i < n; ++i) {
107                 ir_node *op = get_irn_n(irn, i);
108
109                 if (arch_irn_consider_in_reg_alloc(env->cls, op)) {
110                         /* found a register use, create an operand */
111                         o.req     = arch_get_irn_register_req_in(irn, i);
112                         o.carrier = op;
113                         o.irn     = irn;
114                         o.pos     = i;
115                         o.partner = NULL;
116                         o.has_constraints = arch_register_req_is(o.req, limited);
117                         obstack_grow(obst, &o, sizeof(o));
118                         insn->n_ops++;
119                         insn->in_constraints |= o.has_constraints;
120                 }
121         }
122
123         insn->has_constraints = insn->in_constraints | insn->out_constraints;
124         insn->ops = (be_operand_t*)obstack_finish(obst);
125
126         /* Compute the admissible registers bitsets. */
127         for (i = 0; i < insn->n_ops; ++i) {
128                 be_operand_t *op = &insn->ops[i];
129                 const arch_register_req_t   *req = op->req;
130                 const arch_register_class_t *cls = req->cls;
131                 arch_register_req_type_t    type = req->type;
132
133                 /* If there is no special requirement, we allow current class here */
134                 if (cls == NULL && req->type == arch_register_req_type_none) {
135                         cls  = env->cls;
136                         type = arch_register_req_type_normal;
137                 }
138
139                 assert(cls == env->cls);
140
141                 if (type & arch_register_req_type_limited) {
142                         bitset_t *regs = bitset_obstack_alloc(obst, env->cls->n_regs);
143                         rbitset_copy_to_bitset(req->limited, regs);
144                         op->regs = regs;
145                 } else {
146                         op->regs = env->allocatable_regs;
147                 }
148         }
149
150         return insn;
151 }