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
24 #include "irgraph_t.h"
28 #include "besched_t.h"
32 #include "raw_bitset.h"
34 be_insn_t *be_scan_insn(const be_insn_env_t *env, ir_node *irn)
36 const arch_env_t *arch_env = env->aenv;
37 struct obstack *obst = env->obst;
43 insn = obstack_alloc(obst, sizeof(insn[0]));
44 memset(insn, 0, sizeof(insn[0]));
47 insn->next_insn = sched_next(irn);
48 if(get_irn_mode(irn) == mode_T) {
51 for(p = sched_next(irn); is_Proj(p); p = sched_next(p)) {
52 if(arch_irn_consider_in_reg_alloc(arch_env, env->cls, p)) {
53 o.req = arch_get_register_req(arch_env, p, -1);
56 o.pos = -(get_Proj_proj(p) + 1);
58 o.has_constraints = arch_register_req_is(o.req, limited);
59 obstack_grow(obst, &o, sizeof(o));
61 insn->out_constraints |= o.has_constraints;
62 pre_colored += arch_get_irn_register(arch_env, p) != NULL;
67 } else if(arch_irn_consider_in_reg_alloc(arch_env, env->cls, irn)) {
68 o.req = arch_get_register_req(arch_env, irn, -1);
73 o.has_constraints = arch_register_req_is(o.req, limited);
74 obstack_grow(obst, &o, sizeof(o));
76 insn->out_constraints |= o.has_constraints;
77 pre_colored += arch_get_irn_register(arch_env, irn) != NULL;
81 assert(pre_colored == insn->n_ops && "partly pre-colored nodes not supported");
82 insn->pre_colored = 1;
84 insn->use_start = insn->n_ops;
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(arch_env, env->cls, op))
92 o.req = arch_get_register_req(arch_env, irn, i);
97 o.has_constraints = arch_register_req_is(o.req, limited);
98 obstack_grow(obst, &o, sizeof(o));
100 insn->in_constraints |= o.has_constraints;
103 insn->has_constraints = insn->in_constraints | insn->out_constraints;
104 insn->ops = obstack_finish(obst);
106 /* Compute the admissible registers bitsets. */
107 for (i = 0; i < insn->n_ops; ++i) {
108 be_operand_t *op = &insn->ops[i];
109 const arch_register_req_t *req = op->req;
110 const arch_register_class_t *cls = req->cls;
111 arch_register_req_type_t type = req->type;
113 /* If there is no special requirement, we allow current class here */
114 if (cls == NULL && req->type == arch_register_req_type_none) {
116 type = arch_register_req_type_normal;
119 assert(cls == env->cls);
121 op->regs = bitset_obstack_alloc(obst, env->cls->n_regs);
123 if (type & arch_register_req_type_limited) {
124 rbitset_copy_to_bitset(req->limited, op->regs);
126 arch_put_non_ignore_regs(arch_env, env->cls, op->regs);
127 if (env->ignore_colors)
128 bitset_andnot(op->regs, env->ignore_colors);
135 be_insn_env_t *be_insn_env_init(be_insn_env_t *ie, const be_irg_t *birg,
136 const arch_register_class_t *cls,
137 struct obstack *obst)
139 ie->aenv = be_get_birg_arch_env(birg);
142 ie->ignore_colors = bitset_obstack_alloc(obst, cls->n_regs);
143 be_abi_put_ignore_regs(birg->abi, cls, ie->ignore_colors);