2 * Copyright (C) 1995-2007 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
30 #include "irgraph_t.h"
34 #include "besched_t.h"
38 #include "raw_bitset.h"
40 be_insn_t *be_scan_insn(const be_insn_env_t *env, ir_node *irn)
42 const arch_env_t *arch_env = env->aenv;
43 struct obstack *obst = env->obst;
49 insn = obstack_alloc(obst, sizeof(insn[0]));
50 memset(insn, 0, sizeof(insn[0]));
53 insn->next_insn = sched_next(irn);
54 if(get_irn_mode(irn) == mode_T) {
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);
62 o.pos = -(get_Proj_proj(p) + 1);
64 o.has_constraints = arch_register_req_is(o.req, limited);
65 obstack_grow(obst, &o, sizeof(o));
67 insn->out_constraints |= o.has_constraints;
68 pre_colored += arch_get_irn_register(arch_env, p) != NULL;
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);
79 o.has_constraints = arch_register_req_is(o.req, limited);
80 obstack_grow(obst, &o, sizeof(o));
82 insn->out_constraints |= o.has_constraints;
83 pre_colored += arch_get_irn_register(arch_env, irn) != NULL;
87 assert(pre_colored == insn->n_ops && "partly pre-colored nodes not supported");
88 insn->pre_colored = 1;
90 insn->use_start = insn->n_ops;
92 for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
93 ir_node *op = get_irn_n(irn, i);
95 if(!arch_irn_consider_in_reg_alloc(arch_env, env->cls, op))
98 o.req = arch_get_register_req(arch_env, irn, i);
103 o.has_constraints = arch_register_req_is(o.req, limited);
104 obstack_grow(obst, &o, sizeof(o));
106 insn->in_constraints |= o.has_constraints;
109 insn->has_constraints = insn->in_constraints | insn->out_constraints;
110 insn->ops = obstack_finish(obst);
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;
119 /* If there is no special requirement, we allow current class here */
120 if (cls == NULL && req->type == arch_register_req_type_none) {
122 type = arch_register_req_type_normal;
125 assert(cls == env->cls);
127 op->regs = bitset_obstack_alloc(obst, env->cls->n_regs);
129 if (type & arch_register_req_type_limited) {
130 rbitset_copy_to_bitset(req->limited, op->regs);
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);
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)
145 ie->aenv = be_get_birg_arch_env(birg);
148 ie->ignore_colors = bitset_obstack_alloc(obst, cls->n_regs);
149 be_abi_put_ignore_regs(birg->abi, cls, ie->ignore_colors);