#include "config.h"
#endif
-#ifdef WIN32
-#include <malloc.h>
-#else
-#include <alloca.h>
+#ifdef HAVE_MALLOC_H
+ #include <malloc.h>
+#endif
+#ifdef HAVE_ALLOCA_H
+ #include <alloca.h>
#endif
#include <stdio.h>
#include "phiclass.h"
#include "beraextern.h"
+#include "beabi.h"
#include "bearch.h"
#include "benode_t.h"
#include "beirgmod.h"
-#include "besched.h"
+#include "besched_t.h"
#include "beutil.h"
#include "belive_t.h"
+#include "beinsn_t.h"
#define DBG_LEVEL 2
* Environment with all the needed stuff
*/
typedef struct _be_raext_env_t {
- firm_dbg_module_t *dbg;
arch_env_t *aenv;
const arch_register_class_t *cls;
ir_graph *irg;
set *vars; /**< contains all var_info_t */
int n_cls_vars; /**< length of the array cls_vars */
var_info_t **cls_vars; /**< only the var_infos for current cls. needed for double iterating */
+ DEBUG_ONLY(firm_dbg_module_t *dbg;)
} be_raext_env_t;
|_|
*****************************************************************************/
-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);
- const ir_edge_t *edge;
+ 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);
- foreach_out_edge(irn, edge)
- set_irn_n(edge->src, edge->pos, cpy);
+ 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_block_walk_graph(raenv->irg, NULL, handle_constraints_walker, raenv);
+ irg_block_walk_graph(raenv->irg, NULL, handle_constraints_block, raenv);
}
if (has_been_done(start_phi, pos))
return NULL;
- /* In case this is a 'normal' phi we insert into
- * the schedule before the pred_blk irn */
- last_cpy = pred_blk;
+ /* In case this is a 'normal' phi we insert at the
+ * end of the pred block before cf nodes */
+ last_cpy = sched_skip(pred_blk, 0, sched_skip_cf_predicator, raenv->aenv);
+ last_cpy = sched_next(last_cpy);
/* If we detect a loop stop recursion. */
if (arg == start_phi) {
/* At least 2 phis are involved */
/* Insert a loop breaking copy (an additional variable T) */
loop_breaker = be_new_Copy(raenv->cls, raenv->irg, pred_blk, start_phi);
- sched_add_before(pred_blk, loop_breaker);
+ sched_add_before(last_cpy, loop_breaker);
arg = loop_breaker;
}
if (!is_Phi(phi))
break;
+ if (arch_irn_is(raenv->aenv, phi, ignore))
+ continue;
+
raenv->cls = arch_get_irn_reg_class(raenv->aenv, phi, -1);
insert_copies(raenv, phi, pos, phi);
}
int count = 0;
var_info_t *vi;
- raenv->cls_vars = malloc(set_count(raenv->vars) * sizeof(*raenv->cls_vars));
+ raenv->cls_vars = xmalloc(set_count(raenv->vars) * sizeof(*raenv->cls_vars));
assert(raenv->cls_vars);
set_foreach(raenv->vars, vi)
int c_spills=0, c_reloads=0;
pset_foreach(vi->values, irn) {
- if (arch_irn_is_ignore(raenv->aenv, irn) || be_is_Reload(irn)) {
+ if (arch_irn_is(raenv->aenv, irn, ignore) || be_is_Reload(irn)) {
pset_break(vi->values);
return UNSPILLABLE;
}
int pos, max;
var_info_t *vi1, *vi2;
- if (arch_get_irn_reg_class(raenv->aenv, irn, -1) == NULL || arch_irn_is_ignore(raenv->aenv, irn))
+ if (arch_get_irn_reg_class(raenv->aenv, irn, -1) != raenv->cls || arch_irn_is(raenv->aenv, irn, ignore))
return;
vi1 = get_var_info(irn);
/* 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_ignore(raenv->aenv, other)) {
+ if (! arch_irn_is(raenv->aenv, other, ignore)) {
vi2 = get_var_info(other);
fprintf(raenv->f, "(%d, %d, %d)\n", vi1->var_nr, vi2->var_nr, get_affinity_weight(irn));
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, should_be_same) && arch_irn_is_ignore(raenv->aenv, req.other_same)) {
+ if (arch_register_req_is(&req, should_be_same) && arch_irn_is(raenv->aenv, req.other_same, ignore)) {
vi2 = get_var_info(req.other_same);
fprintf(raenv->f, "(%d, %d, %d)\n", vi1->var_nr, vi2->var_nr, get_affinity_weight(irn));
var_info_t *vi;
compute_doms(irg);
+ edges_assure(irg);
raenv.irg = irg;
raenv.aenv = env->arch_env;
raenv.dom_info = be_compute_dominance_frontiers(irg);
raenv.vars = new_set(compare_var_infos, 64);
- raenv.dbg = firm_dbg_register("ir.be.raextern");
- firm_dbg_set_mask(raenv.dbg, DBG_LEVEL);
+ 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" */
dump_to_file(&raenv, out);
execute(callee, out, in);
done = read_and_apply_results(&raenv, in);
+ be_abi_fix_stack_nodes(bi->abi);
ir_snprintf(in, sizeof(in), "-extern-%s-round-%d", raenv.cls->name, round);
be_dump(irg, in, dump_ir_block_graph_sched);