beinsn: Do not store the register requirements in struct be_operand_t.
[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 "bechordal_t.h"
33 #include "besched.h"
34 #include "beinsn_t.h"
35 #include "beabi.h"
36 #include "raw_bitset.h"
37
38 be_insn_t *be_scan_insn(be_chordal_env_t const *const env, ir_node *const irn)
39 {
40         struct obstack *obst = env->obst;
41         be_operand_t o;
42         int i, n;
43
44         be_insn_t *insn = OALLOCZ(obst, be_insn_t);
45
46         bool has_constraints = false;
47
48         insn->irn = irn;
49         if (get_irn_mode(irn) == mode_T) {
50                 ir_node *p;
51
52                 /* This instruction might create more than one def. These are handled
53                    by Proj's, find them. */
54                 foreach_out_edge(irn, edge) {
55                         p = get_edge_src_irn(edge);
56
57                         /* did not work if the result is a ProjT. This should NOT happen
58                            in the backend, but check it for now. */
59                         assert(get_irn_mode(p) != mode_T);
60
61                         if (arch_irn_consider_in_reg_alloc(env->cls, p)) {
62                                 /* found a def: create a new operand */
63                                 arch_register_req_t const *const req = arch_get_irn_register_req(p);
64                                 if (arch_register_req_is(req, limited)) {
65                                         o.regs          = req->limited;
66                                         has_constraints = true;
67                                 } else {
68                                         o.regs           = env->allocatable_regs->data;
69                                         has_constraints |= req->width > 1;
70                                 }
71                                 o.carrier         = p;
72                                 o.partner         = NULL;
73                                 obstack_grow(obst, &o, sizeof(o));
74                                 insn->n_ops++;
75                         }
76                 }
77         } else if (arch_irn_consider_in_reg_alloc(env->cls, irn)) {
78                 /* only one def, create one operand */
79                 arch_register_req_t const *const req = arch_get_irn_register_req(irn);
80                 if (arch_register_req_is(req, limited)) {
81                         o.regs          = req->limited;
82                         has_constraints = true;
83                 } else {
84                         o.regs           = env->allocatable_regs->data;
85                         has_constraints |= req->width > 1;
86                 }
87                 o.carrier = irn;
88                 o.partner = NULL;
89                 obstack_grow(obst, &o, sizeof(o));
90                 insn->n_ops++;
91         }
92
93         insn->use_start = insn->n_ops;
94
95         /* now collect the uses for this node */
96         for (i = 0, n = get_irn_arity(irn); i < n; ++i) {
97                 ir_node *op = get_irn_n(irn, i);
98
99                 if (arch_irn_consider_in_reg_alloc(env->cls, op)) {
100                         /* found a register use, create an operand */
101                         arch_register_req_t const *const req = arch_get_irn_register_req_in(irn, i);
102                         if (arch_register_req_is(req, limited)) {
103                                 o.regs          = req->limited;
104                                 has_constraints = true;
105                         } else {
106                                 o.regs = env->allocatable_regs->data;
107                         }
108                         o.carrier = op;
109                         o.partner = NULL;
110                         obstack_grow(obst, &o, sizeof(o));
111                         insn->n_ops++;
112                 }
113         }
114
115         if (!has_constraints)
116                 return NULL;
117
118         insn->ops = (be_operand_t*)obstack_finish(obst);
119         return insn;
120 }