#include "irnode_t.h"
#include "ircons_t.h"
#include "irprintf.h"
+#include "irgwalk.h"
#include "be_t.h"
#include "belive_t.h"
ir_op *op_be_Perm;
ir_op *op_be_Copy;
ir_op *op_be_Keep;
+ir_op *op_be_CopyKeep;
ir_op *op_be_Call;
ir_op *op_be_Return;
ir_op *op_be_IncSP;
-ir_op *op_be_Alloca;
+ir_op *op_be_AddSP;
ir_op *op_be_SetSP;
ir_op *op_be_RegParams;
ir_op *op_be_StackParam;
ir_op *op_be_FrameAddr;
ir_op *op_be_FrameLoad;
ir_op *op_be_FrameStore;
+ir_op *op_be_Barrier;
static int beo_base = -1;
op_be_Perm = new_ir_op(beo_base + beo_Perm, "Perm", op_pin_state_pinned, N, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
op_be_Copy = new_ir_op(beo_base + beo_Copy, "Copy", op_pin_state_floats, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
op_be_Keep = new_ir_op(beo_base + beo_Keep, "Keep", op_pin_state_pinned, K, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
- op_be_Call = new_ir_op(beo_base + beo_Call, "Call", op_pin_state_pinned, N, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
+ op_be_CopyKeep = new_ir_op(beo_base + beo_CopyKeep, "CopyKeep", op_pin_state_pinned, K, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
+ op_be_Call = new_ir_op(beo_base + beo_Call, "Call", op_pin_state_pinned, N, oparity_variable, 0, sizeof(be_call_attr_t), &be_node_op_ops);
op_be_Return = new_ir_op(beo_base + beo_Return, "Return", op_pin_state_pinned, X, oparity_variable, 0, sizeof(be_node_attr_t), &be_node_op_ops);
- op_be_Alloca = new_ir_op(beo_base + beo_Alloca, "Alloca", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
+ op_be_AddSP = new_ir_op(beo_base + beo_AddSP, "AddSP", op_pin_state_pinned, N, oparity_unary, 0, sizeof(be_node_attr_t), &be_node_op_ops);
op_be_SetSP = new_ir_op(beo_base + beo_SetSP, "SetSP", op_pin_state_pinned, N, oparity_binary, 0, sizeof(be_stack_attr_t), &be_node_op_ops);
op_be_IncSP = new_ir_op(beo_base + beo_IncSP, "IncSP", op_pin_state_pinned, N, oparity_binary, 0, sizeof(be_stack_attr_t), &be_node_op_ops);
op_be_RegParams = new_ir_op(beo_base + beo_RegParams, "RegParams", op_pin_state_pinned, N, oparity_zero, 0, sizeof(be_node_attr_t), &be_node_op_ops);
op_be_FrameAddr = new_ir_op(beo_base + beo_FrameAddr, "FrameAddr", op_pin_state_pinned, N, oparity_binary, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
op_be_FrameLoad = new_ir_op(beo_base + beo_FrameLoad, "FrameLoad", op_pin_state_pinned, N, oparity_any, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
op_be_FrameStore = new_ir_op(beo_base + beo_FrameStore, "FrameStore", op_pin_state_pinned, N, oparity_any, 0, sizeof(be_frame_attr_t), &be_node_op_ops);
+ op_be_Barrier = new_ir_op(beo_base + beo_Barrier, "Barrier", op_pin_state_pinned, N, oparity_any, 0, sizeof(be_node_attr_t), &be_node_op_ops);
set_op_tag(op_be_Spill, &be_node_tag);
set_op_tag(op_be_Reload, &be_node_tag);
set_op_tag(op_be_Perm, &be_node_tag);
set_op_tag(op_be_Copy, &be_node_tag);
set_op_tag(op_be_Keep, &be_node_tag);
+ set_op_tag(op_be_CopyKeep, &be_node_tag);
set_op_tag(op_be_Call, &be_node_tag);
set_op_tag(op_be_Return, &be_node_tag);
- set_op_tag(op_be_Alloca, &be_node_tag);
+ set_op_tag(op_be_AddSP, &be_node_tag);
set_op_tag(op_be_SetSP, &be_node_tag);
set_op_tag(op_be_IncSP, &be_node_tag);
set_op_tag(op_be_RegParams, &be_node_tag);
set_op_tag(op_be_FrameLoad, &be_node_tag);
set_op_tag(op_be_FrameStore, &be_node_tag);
set_op_tag(op_be_FrameAddr, &be_node_tag);
+ set_op_tag(op_be_Barrier, &be_node_tag);
}
static void *init_node_attr(ir_node* irn, int max_reg_data)
ir_node *(be_get_Reload_mem)(const ir_node *irn)
{
assert(be_is_Reload(irn));
- return get_irn_n(irn, 1);
+ return get_irn_n(irn, be_pos_Reload_mem);
}
ir_node *be_new_Perm(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, int n, ir_node *in[])
return irn;
}
-ir_node *be_new_Alloca(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *mem, ir_node *old_sp, ir_node *sz)
+ir_node *be_new_AddSP(const arch_register_t *sp, ir_graph *irg, ir_node *bl, ir_node *old_sp, ir_node *sz)
{
be_node_attr_t *a;
ir_node *irn;
- ir_node *in[3];
+ ir_node *in[be_pos_AddSP_last];
- in[0] = mem;
- in[1] = old_sp;
- in[2] = sz;
- irn = new_ir_node(NULL, irg, bl, op_be_Alloca, mode_T, 3, in);
- a = init_node_attr(irn, 3);
+ in[be_pos_AddSP_old_sp] = old_sp;
+ in[be_pos_AddSP_size] = sz;
+
+ irn = new_ir_node(NULL, irg, bl, op_be_AddSP, mode_T, be_pos_AddSP_last, in);
+ a = init_node_attr(irn, be_pos_AddSP_last);
- be_node_set_flags(irn, OUT_POS(pn_Alloc_res), arch_irn_flags_ignore);
+ be_node_set_flags(irn, OUT_POS(0), arch_irn_flags_ignore);
/* Set output constraint to stack register. */
- be_set_constr_single_reg(irn, OUT_POS(pn_Alloc_res), sp);
+ be_set_constr_single_reg(irn, OUT_POS(0), sp);
return irn;
}
return irn;
}
+ir_node *be_new_CopyKeep(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *src, int n, ir_node *in_keep[], ir_mode *mode)
+{
+ ir_node *irn;
+ ir_node **in = (ir_node **) alloca((n + 1) * sizeof(in[0]));
+
+ in[0] = src;
+ memcpy(&in[1], in_keep, n * sizeof(in[0]));
+ irn = new_ir_node(NULL, irg, bl, op_be_CopyKeep, mode, n + 1, in);
+ init_node_attr(irn, n);
+ be_node_set_reg_class(irn, OUT_POS(0), cls);
+ be_node_set_reg_class(irn, 0, cls);
+
+ return irn;
+}
+
+ir_node *be_new_CopyKeep_single(const arch_register_class_t *cls, ir_graph *irg, ir_node *bl, ir_node *src, ir_node *keep, ir_mode *mode)
+{
+ ir_node *in[1];
+
+ in[0] = keep;
+ return be_new_CopyKeep(cls, irg, bl, src, 1, in, mode);
+}
+
+ir_node *be_new_Barrier(ir_graph *irg, ir_node *bl, int n, ir_node *in[])
+{
+ ir_node *irn;
+
+ irn = new_ir_node(NULL, irg, bl, op_be_Barrier, mode_T, n, in);
+ init_node_attr(irn, n);
+ return irn;
+}
+
int be_is_Spill (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Spill ; }
int be_is_Reload (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Reload ; }
int be_is_Copy (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Copy ; }
int be_is_Return (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Return ; }
int be_is_IncSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_IncSP ; }
int be_is_SetSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_SetSP ; }
-int be_is_Alloca (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Alloca ; }
+int be_is_AddSP (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_AddSP ; }
int be_is_RegParams (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_RegParams ; }
int be_is_StackParam (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_StackParam ; }
int be_is_FrameAddr (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameAddr ; }
int be_is_FrameLoad (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameLoad ; }
int be_is_FrameStore (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_FrameStore ; }
+int be_is_Barrier (const ir_node *irn) { return be_get_irn_opcode(irn) == beo_Barrier ; }
int be_has_frame_entity(const ir_node *irn)
{
return NULL;
}
-static void entity_copy_walker(ir_node *irn, void *data)
+static void link_reload_walker(ir_node *irn, void *data)
{
+ ir_node **root = (ir_node **) data;
if(be_is_Reload(irn)) {
- be_frame_attr_t *a = get_irn_attr(irn);
- entity *ent = be_get_spill_entity(irn);
-
- a->ent = ent;
+ set_irn_link(irn, *root);
+ *root = irn;
}
}
void be_copy_entities_to_reloads(ir_graph *irg)
{
- irg_walk_graph(irg, entity_copy_walker, NULL, NULL);
+ ir_node *irn = NULL;
+ irg_walk_graph(irg, link_reload_walker, NULL, (void *) &irn);
+
+ while(irn) {
+ be_frame_attr_t *a = get_irn_attr(irn);
+ entity *ent = be_get_spill_entity(irn);
+ a->ent = ent;
+ irn = get_irn_link(irn);
+ }
}
ir_node *be_spill(const arch_env_t *arch_env, ir_node *irn, ir_node *ctx)
{
- ir_node *bl = get_nodes_block(irn);
- ir_graph *irg = get_irn_irg(bl);
- ir_node *frame = get_irg_frame(irg);
+ ir_node *bl = get_nodes_block(irn);
+ ir_graph *irg = get_irn_irg(bl);
+ ir_node *frame = get_irg_frame(irg);
+ ir_node *insert = bl;
ir_node *spill;
- ir_node *insert;
const arch_register_class_t *cls = arch_get_irn_reg_class(arch_env, irn, -1);
const arch_register_class_t *cls_frame = arch_get_irn_reg_class(arch_env, frame, -1);
* directly after the phi, if there are some phis behind the one which
* is spilled. Also, a spill of a Proj must be after all Projs of the
* same tuple node.
- */
- insert = sched_next(irn);
- while((is_Phi(insert) || is_Proj(insert)) && !sched_is_end(insert))
- insert = sched_next(insert);
-
- /*
+ *
* Here's one special case:
* If the spill is in the start block, the spill must be after the frame
- * pointer is set up. This is checked here and fixed.
+ * pointer is set up. This is done by setting insert to the end of the block
+ * which is its default initialization (see above).
*/
- if(bl == get_irg_start_block(irg))
- insert = sched_next(frame);
+ if(bl != get_irg_start_block(irg)) {
+ insert = sched_next(irn);
+ while((is_Phi(insert) || is_Proj(insert)) && !sched_is_end(insert))
+ insert = sched_next(insert);
+ }
sched_add_before(insert, spill);
return spill;
};
-static void dump_node_req(FILE *f, be_req_t *req)
+static void dump_node_req(FILE *f, int idx, be_req_t *req)
{
unsigned i;
int did_something = 0;
- const char *suffix = "";
+ char buf[16];
+ const char *prefix = buf;
+
+ snprintf(buf, sizeof(buf), "#%d ", idx);
if(req->flags != arch_irn_flags_none) {
- fprintf(f, "flags: ");
+ fprintf(f, "%sflags: ", prefix);
+ prefix = "";
for(i = arch_irn_flags_none; i <= log2_ceil(arch_irn_flags_last); ++i) {
if(req->flags & (1 << i)) {
- fprintf(f, "%s%s", suffix, arch_irn_flag_str(1 << i));
- suffix = "|";
+ fprintf(f, "%s%s", prefix, arch_irn_flag_str(1 << i));
+ prefix = "|";
}
}
- suffix = ", ";
+ prefix = ", ";
did_something = 1;
}
if(req->req.cls != 0) {
char tmp[256];
- fprintf(f, suffix);
+ fprintf(f, prefix);
arch_register_req_format(tmp, sizeof(tmp), &req->req);
fprintf(f, "%s", tmp);
did_something = 1;
fprintf(f, "in requirements\n");
for(i = 0; i < a->max_reg_data; ++i) {
- dump_node_req(f, &a->reg_data[i].in_req);
+ dump_node_req(f, i, &a->reg_data[i].in_req);
}
fprintf(f, "\nout requirements\n");
for(i = 0; i < a->max_reg_data; ++i) {
- dump_node_req(f, &a->reg_data[i].req);
+ dump_node_req(f, i, &a->reg_data[i].req);
}
}
dump_node,
NULL
};
-
-pset *nodes_live_at(const arch_env_t *arch_env, const arch_register_class_t *cls, const ir_node *pos, pset *live)
-{
- firm_dbg_module_t *dbg = firm_dbg_register("firm.be.node");
- const ir_node *bl = is_Block(pos) ? pos : get_nodes_block(pos);
- ir_node *irn;
- irn_live_t *li;
-
- live_foreach(bl, li) {
- ir_node *irn = (ir_node *) li->irn;
- if(live_is_end(li) && arch_irn_consider_in_reg_alloc(arch_env, cls, irn))
- pset_insert_ptr(live, irn);
- }
-
- sched_foreach_reverse(bl, irn) {
- int i, n;
- ir_node *x;
-
- /*
- * If we encounter the node we want to insert the Perm after,
- * exit immediately, so that this node is still live
- */
- if(irn == pos)
- return live;
-
- DBG((dbg, LEVEL_1, "%+F\n", irn));
- for(x = pset_first(live); x; x = pset_next(live))
- DBG((dbg, LEVEL_1, "\tlive: %+F\n", x));
-
- if(arch_irn_consider_in_reg_alloc(arch_env, cls, irn))
- pset_remove_ptr(live, irn);
-
- for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
- ir_node *op = get_irn_n(irn, i);
-
- if(arch_irn_consider_in_reg_alloc(arch_env, cls, op))
- pset_insert_ptr(live, op);
- }
- }
-
- return live;
-}
-
-ir_node *insert_Perm_after(const arch_env_t *arch_env,
- const arch_register_class_t *cls,
- dom_front_info_t *dom_front,
- ir_node *pos)
-{
- ir_node *bl = is_Block(pos) ? pos : get_nodes_block(pos);
- ir_graph *irg = get_irn_irg(bl);
- pset *live = pset_new_ptr_default();
- firm_dbg_module_t *dbg = firm_dbg_register("be.node");
-
- ir_node *curr, *irn, *perm, **nodes;
- int i, n;
-
- DBG((dbg, LEVEL_1, "Insert Perm after: %+F\n", pos));
-
- if(!nodes_live_at(arch_env, cls, pos, live));
-
- n = pset_count(live);
-
- if(n == 0)
- return NULL;
-
- nodes = malloc(n * sizeof(nodes[0]));
-
- DBG((dbg, LEVEL_1, "live:\n"));
- for(irn = pset_first(live), i = 0; irn; irn = pset_next(live), i++) {
- DBG((dbg, LEVEL_1, "\t%+F\n", irn));
- nodes[i] = irn;
- }
-
- perm = be_new_Perm(cls, irg, bl, n, nodes);
- sched_add_after(pos, perm);
- free(nodes);
-
- curr = perm;
- for(i = 0; i < n; ++i) {
- ir_node *copies[2];
- ir_node *perm_op = get_irn_n(perm, i);
- const arch_register_t *reg = arch_get_irn_register(arch_env, perm_op);
-
- ir_mode *mode = get_irn_mode(perm_op);
- ir_node *proj = new_r_Proj(irg, bl, perm, mode, i);
- arch_set_irn_register(arch_env, proj, reg);
-
- sched_add_after(curr, proj);
- curr = proj;
-
- copies[0] = perm_op;
- copies[1] = proj;
- be_ssa_constr(dom_front, 2, copies);
- }
- return perm;
-}