#include "besched_t.h"
#include "beutil.h"
#include "belive_t.h"
+#include "beinsn_t.h"
#define DBG_LEVEL 2
|_|
*****************************************************************************/
-static void handle_constraints_walker(ir_node *irn, void *env) {
- be_raext_env_t *raenv = env;
- arch_register_req_t req;
- int pos, max;
+static void handle_constraints_insn(be_raext_env_t *env, be_insn_t *insn)
+{
+ ir_node *bl = get_nodes_block(insn->irn);
+ int i;
- /* handle output constraints
- * user -> irn becomes user -> cpy -> irn
- */
- arch_get_register_req(raenv->aenv, &req, irn, -1);
- if (arch_register_req_is(&req, limited)) {
- ir_node *cpy = be_new_Copy(req.cls, raenv->irg, get_nodes_block(irn), irn);
+ for(i = 0; i < insn->use_start; ++i) {
+ be_operand_t *op = &insn->ops[i];
- /* all users of the irn use the copy instead */
- sched_add_after(irn, cpy);
- edges_reroute(irn, cpy, raenv->irg);
+ if(op->has_constraints) {
+ ir_node *cpy = be_new_Copy(op->req.cls, env->irg, bl, op->carrier);
+ sched_add_before(insn->next_insn, cpy);
+ edges_reroute(op->carrier, cpy, env->irg);
+ }
}
+ for(i = insn->use_start; i < insn->n_ops; ++i) {
+ be_operand_t *op = &insn->ops[i];
- /* handle input constraints by converting them into output constraints
- * of copies of the former argument
- * irn -> arg becomes irn -> copy -> arg
- */
- for (pos = 0, max = get_irn_arity(irn); pos<max; ++pos) {
- arch_get_register_req(raenv->aenv, &req, irn, pos);
- if (arch_register_req_is(&req, limited)) {
- ir_node *arg = get_irn_n(irn, pos);
- ir_node *cpy = be_new_Copy(req.cls, raenv->irg, get_nodes_block(irn), arg);
+ if(op->has_constraints) {
+ ir_node *cpy = be_new_Copy(op->req.cls, env->irg, bl, op->carrier);
+ sched_add_before(insn->irn, cpy);
+ set_irn_n(insn->irn, op->pos, cpy);
+ be_set_constr_limited(cpy, BE_OUT_POS(0), &op->req);
+ }
+ }
+}
- /* use the copy instead */
- sched_add_before(irn, cpy);
- set_irn_n(irn, pos, cpy);
+static void handle_constraints_block(ir_node *bl, void *data)
+{
+ be_raext_env_t *raenv = data;
+ int active = bl != get_irg_start_block(raenv->irg);
- /* set an out constraint for the copy */
- be_set_constr_limited(cpy, -1, &req);
- }
+ ir_node *irn;
+ be_insn_env_t ie;
+ struct obstack obst;
+
+ ie.cls = raenv->cls;
+ ie.aenv = raenv->aenv;
+ ie.obst = &obst;
+ ie.ignore_colors = NULL;
+ obstack_init(&obst);
+
+ irn = sched_first(bl);
+ while(!sched_is_end(irn)) {
+ be_insn_t *insn = be_scan_insn(&ie, irn);
+
+ if(insn->has_constraints)
+ handle_constraints_insn(raenv, insn);
+
+ if(be_is_Barrier(irn))
+ active = !active;
+
+ irn = insn->next_insn;
+ obstack_free(&obst, insn);
}
}
static void handle_constraints(be_raext_env_t *raenv) {
- irg_walk_graph(raenv->irg, NULL, handle_constraints_walker, raenv);
+ irg_block_walk_graph(raenv->irg, NULL, handle_constraints_block, raenv);
}
/* copies have affinities */
if (arch_irn_classify(raenv->aenv, irn) == arch_irn_class_copy) {
- ir_node *other = get_irn_n(irn, be_pos_Copy_orig);
+ ir_node *other = be_get_Copy_op(irn);
if (! arch_irn_is(raenv->aenv, other, ignore)) {
vi2 = get_var_info(other);
FIRM_DBG_REGISTER(raenv.dbg, "firm.be.raextern");
/* Insert copies for constraints */
- handle_constraints(&raenv);
+ for(clsnr = 0, clss = arch_isa_get_n_reg_class(raenv.aenv->isa); clsnr < clss; ++clsnr) {
+ raenv.cls = arch_isa_get_reg_class(raenv.aenv->isa, clsnr);
+ handle_constraints(&raenv);
+ }
+
be_dump(irg, "-extern-constr", dump_ir_block_graph_sched);
/* SSA destruction respectively transformation into "Conventional SSA" */