2 * Copyright (C) 1995-2008 University of Karlsruhe. All right reserved.
4 * This file is part of libFirm.
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.
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.
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
22 * @brief A data structure to treat nodes and node-proj collections uniformly.
23 * @author Sebastian Hack
27 #include "irgraph_t.h"
32 #include "bechordal_t.h"
36 #include "raw_bitset.h"
38 be_insn_t *be_scan_insn(be_chordal_env_t const *const env, ir_node *const irn)
40 struct obstack *obst = env->obst;
44 be_insn_t *insn = OALLOCZ(obst, be_insn_t);
47 if (get_irn_mode(irn) == mode_T) {
50 /* This instruction might create more than one def. These are handled
51 by Proj's, find them. */
52 foreach_out_edge(irn, edge) {
53 p = get_edge_src_irn(edge);
55 /* did not work if the result is a ProjT. This should NOT happen
56 in the backend, but check it for now. */
57 assert(get_irn_mode(p) != mode_T);
59 if (arch_irn_consider_in_reg_alloc(env->cls, p)) {
60 /* found a def: create a new operand */
61 o.req = arch_get_irn_register_req(p);
64 o.pos = -(get_Proj_proj(p) + 1);
66 obstack_grow(obst, &o, sizeof(o));
68 insn->has_constraints |= arch_register_req_is(o.req, limited) | (o.req->width > 1);
71 } else if (arch_irn_consider_in_reg_alloc(env->cls, irn)) {
72 /* only one def, create one operand */
73 o.req = arch_get_irn_register_req(irn);
78 obstack_grow(obst, &o, sizeof(o));
80 insn->has_constraints |= arch_register_req_is(o.req, limited) | (o.req->width > 1);
83 insn->use_start = insn->n_ops;
85 /* now collect the uses for this node */
86 for (i = 0, n = get_irn_arity(irn); i < n; ++i) {
87 ir_node *op = get_irn_n(irn, i);
89 if (arch_irn_consider_in_reg_alloc(env->cls, op)) {
90 /* found a register use, create an operand */
91 o.req = arch_get_irn_register_req_in(irn, i);
96 obstack_grow(obst, &o, sizeof(o));
98 insn->has_constraints |= arch_register_req_is(o.req, limited);
102 insn->ops = (be_operand_t*)obstack_finish(obst);
104 /* Compute the admissible registers bitsets. */
105 for (i = 0; i < insn->n_ops; ++i) {
106 be_operand_t *const op = &insn->ops[i];
107 arch_register_req_t const *const req = op->req;
108 assert(req->cls == env->cls);
110 if (req->type & arch_register_req_type_limited) {
111 bitset_t *regs = bitset_obstack_alloc(obst, env->cls->n_regs);
112 rbitset_copy_to_bitset(req->limited, regs);
115 op->regs = env->allocatable_regs;