changed targets for new_nodes.[ch] creation
[libfirm] / ir / be / bearch_firm.c
index 21747f3..b571693 100644 (file)
@@ -21,7 +21,9 @@
 
 #include "irreflect.h"
 
-#define N_REGS 6
+#include "bearch_firm.h"
+
+#define N_REGS 3
 
 static arch_register_t datab_regs[N_REGS];
 
@@ -32,14 +34,6 @@ static arch_register_class_t reg_classes[] = {
 static ir_op *op_push;
 static ir_op *op_imm;
 
-typedef struct {
-       enum { imm_Const, imm_SymConst } tp;
-       union {
-               tarval *tv;
-               entity *ent;
-       } data;
-} imm_attr_t;
-
 #define N_CLASSES \
   (sizeof(reg_classes) / sizeof(reg_classes[0]))
 
@@ -86,7 +80,7 @@ static void firm_init(void)
                int push_opc = get_next_ir_opcode();
 
                op_push = new_ir_op(push_opc, "Push",
-                               op_pin_state_pinned, 0, oparity_binary, 0, 0);
+                               op_pin_state_pinned, 0, oparity_binary, 0, 0, NULL);
 
                sig = rflct_signature_allocate(1, 3);
                rflct_signature_set_arg(sig, 0, 0, "Store", RFLCT_MC(Mem), 0, 0);
@@ -99,10 +93,18 @@ static void firm_init(void)
        }
 
        if(!op_imm) {
-               op_imm = new_ir_op(get_next_ir_opcode(), "Imm",
-                               op_pin_state_pinned, 0, oparity_zero, 0, sizeof(imm_attr_t));
-       }
+               rflct_sig_t *sig;
+               int imm_opc = get_next_ir_opcode();
+
+               op_imm = new_ir_op(imm_opc, "Imm",
+                               op_pin_state_pinned, 0, oparity_zero, 0, sizeof(imm_attr_t), NULL);
 
+               sig = rflct_signature_allocate(1, 1);
+               rflct_signature_set_arg(sig, 0, 0, "Imm", RFLCT_MC(Data), 0, 0);
+               rflct_signature_set_arg(sig, 1, 0, "Block", RFLCT_MC(BB), 0, 0);
+               rflct_new_opcode(imm_opc, "Imm", false);
+               rflct_opcode_add_signature(imm_opc, sig);
+       }
 }
 
 static int firm_get_n_reg_class(void)
@@ -275,19 +277,27 @@ static ir_node *new_Imm(ir_graph *irg, ir_node *bl, ir_node *cnst)
        res = new_ir_node(NULL, irg, bl, op_imm, get_irn_mode(cnst), 0, ins);
        attr = (imm_attr_t *) &res->attr;
 
-       if(get_irn_opcode(cnst) == iro_SymConst) {
-               attr->tp = imm_SymConst;
-               attr->data.ent = get_SymConst_entity(cnst);
-       }
-
-       else {
-               attr->tp = imm_Const;
-               attr->data.tv = get_Const_tarval(cnst);
+       switch (get_irn_opcode(cnst)) {
+               case iro_Const:
+                       attr->tp = imm_Const;
+                       attr->data.tv = get_Const_tarval(cnst);
+                       break;
+               case iro_SymConst:
+                       attr->tp = imm_SymConst;
+                       //attr->data.ent = get_SymConst_entity(cnst);
+                       break;
+               case iro_Unknown:
+                       break;
+               default:                assert(0 && "Cannot create Imm for this opcode");
        }
 
        return res;
 }
 
+int is_Imm(const ir_node *irn) {
+       return get_irn_op(irn) == op_imm;
+}
+
 static void prepare_walker(ir_node *irn, void *data)
 {
        opcode opc = get_irn_opcode(irn);
@@ -331,16 +341,29 @@ static void prepare_walker(ir_node *irn, void *data)
                        set_irn_link(nc, nc);
                }
        }
+}
 
-       else if(opc == iro_Const || opc == iro_SymConst) {
-               ir_node *bl   = get_nodes_block(irn);
-               ir_graph *irg = get_irn_irg(bl);
-
-               ir_node *imm = new_Imm(irg, bl, irn);
-               exchange(irn, imm);
-               set_irn_link(imm, imm);
+static void localize_const_walker(ir_node *irn, void *data)
+{
+       if(!is_Block(irn)) {
+               int i, n;
+               ir_node *bl = get_nodes_block(irn);
+
+               for(i = 0, n = get_irn_arity(irn); i < n; ++i) {
+                       ir_node *op    = get_irn_n(irn, i);
+                       opcode opc     = get_irn_opcode(op);
+
+                       if(opc == iro_Const
+                       || opc == iro_Unknown
+                       || (opc == iro_SymConst /*&& get_SymConst_kind(op) == symconst_addr_ent*/)) {
+                               ir_graph *irg   = get_irn_irg(bl);
+                               ir_node *imm_bl = is_Phi(irn) ? get_Block_cfgpred_block(bl, i) : bl;
+
+                               ir_node *imm = new_Imm(irg, imm_bl, op);
+                               set_irn_n(irn, i, imm);
+                       }
+               }
        }
-
 }
 
 static void clear_link(ir_node *irn, void *data)
@@ -350,7 +373,7 @@ static void clear_link(ir_node *irn, void *data)
 
 static void firm_prepare_graph(ir_graph *irg)
 {
-       irg_walk_graph(irg, clear_link, NULL, NULL);
+       irg_walk_graph(irg, clear_link, localize_const_walker, NULL);
        irg_walk_graph(irg, NULL, prepare_walker, NULL);
 }