add an get_irg_idx
[libfirm] / ir / ir / irnode.c
index 963928f..e81e212 100644 (file)
@@ -35,7 +35,6 @@
 #include "irnode_t.h"
 #include "irgraph_t.h"
 #include "irmode_t.h"
-#include "typegmod.h"
 #include "irbackedge_t.h"
 #include "irdump.h"
 #include "irop_t.h"
@@ -65,6 +64,8 @@ static const char *pnc_name_arr [] = {
  * returns the pnc name from an pnc constant
  */
 const char *get_pnc_string(int pnc) {
+       assert(pnc >= 0 && pnc <
+                       (int) (sizeof(pnc_name_arr)/sizeof(pnc_name_arr[0])));
        return pnc_name_arr[pnc];
 }
 
@@ -107,7 +108,7 @@ unsigned firm_add_node_size = 0;
 
 
 /* register new space for every node */
-unsigned register_additional_node_data(unsigned size) {
+unsigned firm_register_additional_node_data(unsigned size) {
        assert(!forbid_new_data && "Too late to register additional node data");
 
        if (forbid_new_data)
@@ -130,8 +131,8 @@ init_irnode(void) {
  * If arity is negative, a node with a dynamic array is created.
  */
 ir_node *
-new_ir_node (dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mode,
-         int arity, ir_node **in)
+new_ir_node(dbg_info *db, ir_graph *irg, ir_node *block, ir_op *op, ir_mode *mode,
+            int arity, ir_node **in)
 {
        ir_node *res;
        size_t node_size = offsetof(ir_node, attr) + op->attr_size + firm_add_node_size;
@@ -430,7 +431,7 @@ void
        _set_irn_op(node, op);
 }
 
-ir_opcode
+unsigned
 (get_irn_opcode)(const ir_node *node) {
        return _get_irn_opcode(node);
 }
@@ -522,10 +523,22 @@ void firm_set_irn_section(ir_node *n, struct section *s) {
 }
 #else
 /* Dummies needed for firmjni. */
-struct abstval *get_irn_abst_value(ir_node *n) { return NULL; }
-void set_irn_abst_value(ir_node *n, struct abstval *os) {}
-struct section *firm_get_irn_section(ir_node *n) { return NULL; }
-void firm_set_irn_section(ir_node *n, struct section *s) {}
+struct abstval *get_irn_abst_value(ir_node *n) {
+       (void) n;
+       return NULL;
+}
+void set_irn_abst_value(ir_node *n, struct abstval *os) {
+       (void) n;
+       (void) os;
+}
+struct section *firm_get_irn_section(ir_node *n) {
+       (void) n;
+       return NULL;
+}
+void firm_set_irn_section(ir_node *n, struct section *s) {
+       (void) n;
+       (void) s;
+}
 #endif /* DO_HEAPANALYSIS */
 
 
@@ -539,10 +552,10 @@ long get_irn_node_nr(const ir_node *node) {
 #endif
 }
 
-const_attr
+const_attr *
 get_irn_const_attr(ir_node *node) {
        assert(node->op == op_Const);
-       return node->attr.con;
+       return &node->attr.con;
 }
 
 long
@@ -551,22 +564,22 @@ get_irn_proj_attr(ir_node *node) {
        return node->attr.proj;
 }
 
-alloc_attr
+alloc_attr *
 get_irn_alloc_attr(ir_node *node) {
        assert(node->op == op_Alloc);
-       return node->attr.alloc;
+       return &node->attr.alloc;
 }
 
-free_attr
+free_attr *
 get_irn_free_attr(ir_node *node) {
        assert(node->op == op_Free);
-       return node->attr.free;
+       return &node->attr.free;
 }
 
-symconst_attr
+symconst_attr *
 get_irn_symconst_attr(ir_node *node) {
        assert(node->op == op_SymConst);
-       return node->attr.symc;
+       return &node->attr.symc;
 }
 
 ir_type *
@@ -575,10 +588,10 @@ get_irn_call_attr(ir_node *node) {
        return node->attr.call.cld_tp = skip_tid(node->attr.call.cld_tp);
 }
 
-sel_attr
+sel_attr *
 get_irn_sel_attr(ir_node *node) {
        assert(node->op == op_Sel);
-       return node->attr.sel;
+       return &node->attr.sel;
 }
 
 int
@@ -587,29 +600,29 @@ get_irn_phi0_attr(ir_node *node) {
        return node->attr.phi0.pos;
 }
 
-block_attr
+block_attr *
 get_irn_block_attr(ir_node *node) {
        assert(node->op == op_Block);
-       return node->attr.block;
+       return &node->attr.block;
 }
 
-load_attr
+load_attr *
 get_irn_load_attr(ir_node *node) {
        assert(node->op == op_Load);
-       return node->attr.load;
+       return &node->attr.load;
 }
 
-store_attr
+store_attr *
 get_irn_store_attr(ir_node *node) {
        assert(node->op == op_Store);
-       return node->attr.store;
+       return &node->attr.store;
 }
 
-except_attr
+except_attr *
 get_irn_except_attr(ir_node *node) {
        assert(node->op == op_Div || node->op == op_Quot ||
               node->op == op_DivMod || node->op == op_Mod || node->op == op_Call || node->op == op_Alloc);
-       return node->attr.except;
+       return &node->attr.except;
 }
 
 void *(get_irn_generic_attr)(ir_node *node) {
@@ -642,7 +655,6 @@ int get_irn_pred_pos(ir_node *node, ir_node *arg) {
 ir_node *
 get_nodes_block(const ir_node *node) {
        assert(node->op != op_Block);
-       assert(is_irn_pinned_in_irg(node) && "block info may be incorrect");
        return get_irn_n(node, -1);
 }
 
@@ -652,6 +664,13 @@ set_nodes_block(ir_node *node, ir_node *block) {
        set_irn_n(node, -1, block);
 }
 
+/* this works for all except Block */
+ir_node *
+get_nodes_MacroBlock(const ir_node *node) {
+       assert(node->op != op_Block);
+       return get_Block_MacroBlock(get_irn_n(node, -1));
+}
+
 /* Test whether arbitrary node is frame pointer, i.e. Proj(pn_Start_P_frame_base)
  * from Start.  If so returns frame type, else Null. */
 ir_type *is_frame_pointer(ir_node *n) {
@@ -714,7 +733,7 @@ int
 }
 
 ir_node *
-(get_Block_cfgpred)(ir_node *node, int pos) {
+(get_Block_cfgpred)(const ir_node *node, int pos) {
        return _get_Block_cfgpred(node, pos);
 }
 
@@ -725,12 +744,12 @@ set_Block_cfgpred(ir_node *node, int pos, ir_node *pred) {
 }
 
 ir_node  *
-(get_Block_cfgpred_block)(ir_node *node, int pos) {
+(get_Block_cfgpred_block)(const ir_node *node, int pos) {
        return _get_Block_cfgpred_block(node, pos);
 }
 
 int
-get_Block_matured(ir_node *node) {
+get_Block_matured(const ir_node *node) {
        assert(node->op == op_Block);
        return (int)node->attr.block.is_matured;
 }
@@ -779,6 +798,7 @@ set_Block_graph_arr (ir_node *node, int pos, ir_node *value) {
        node->attr.block.graph_arr[pos+1] = value;
 }
 
+#ifdef INTERPROCEDURAL_VIEW
 void set_Block_cg_cfgpred_arr(ir_node *node, int arity, ir_node *in[]) {
        assert(node->op == op_Block);
        if (node->attr.block.in_cg == NULL || arity != ARR_LEN(node->attr.block.in_cg) - 1) {
@@ -823,6 +843,7 @@ void remove_Block_cg_cfgpred_arr(ir_node *node) {
        assert(node->op == op_Block);
        node->attr.block.in_cg = NULL;
 }
+#endif
 
 ir_node *(set_Block_dead)(ir_node *block) {
        return _set_Block_dead(block);
@@ -846,9 +867,37 @@ void set_Block_extbb(ir_node *block, ir_extblk *extblk) {
        block->attr.block.extblk = extblk;
 }
 
+/* returns the macro block header of a block. */
 ir_node *get_Block_MacroBlock(const ir_node *block) {
+       ir_node *mbh;
        assert(is_Block(block));
-       return get_irn_n(block, -1);
+       mbh = get_irn_n(block, -1);
+       /* once macro block header is respected by all optimizations,
+          this assert can be removed */
+       assert(mbh != NULL);
+       return mbh;
+}
+
+/* returns the graph of a Block. */
+ir_graph *get_Block_irg(const ir_node *block) {
+       assert(is_Block(block));
+       return block->attr.block.irg;
+}
+
+int has_Block_label(const ir_node *block) {
+       assert(is_Block(block));
+       return block->attr.block.has_label;
+}
+
+ir_label_t get_Block_label(const ir_node *block) {
+       assert(is_Block(block));
+       return block->attr.block.label;
+}
+
+void set_Block_label(ir_node *block, ir_label_t label) {
+       assert(is_Block(block));
+       block->attr.block.has_label = 1;
+       block->attr.block.label = label;
 }
 
 int
@@ -1052,8 +1101,16 @@ set_Const_tarval(ir_node *node, tarval *con) {
        node->attr.con.tv = con;
 }
 
-cnst_classify_t (classify_Const)(ir_node *node) {
-       return _classify_Const(node);
+int (is_Const_null)(const ir_node *node) {
+       return _is_Const_null(node);
+}
+
+int (is_Const_one)(const ir_node *node) {
+       return _is_Const_one(node);
+}
+
+int (is_Const_all_one)(const ir_node *node) {
+       return _is_Const_all_one(node);
 }
 
 
@@ -1063,6 +1120,7 @@ cnst_classify_t (classify_Const)(ir_node *node) {
 ir_type *
 get_Const_type(ir_node *node) {
        assert(node->op == op_Const);
+       node->attr.con.tp = skip_tid(node->attr.con.tp);
        return node->attr.con.tp;
 }
 
@@ -1149,6 +1207,16 @@ set_SymConst_symbol(ir_node *node, union symconst_symbol sym) {
        node->attr.symc.sym = sym;
 }
 
+ir_label_t get_SymConst_label(const ir_node *node) {
+       assert(node->op == op_SymConst && SYMCONST_HAS_LABEL(get_SymConst_kind(node)));
+       return node->attr.symc.sym.label;
+}
+
+void set_SymConst_label(ir_node *node, ir_label_t label) {
+       assert(node->op == op_SymConst && SYMCONST_HAS_LABEL(get_SymConst_kind(node)));
+       node->attr.symc.sym.label = label;
+}
+
 ir_type *
 get_SymConst_value_type(ir_node *node) {
        assert(node->op == op_SymConst);
@@ -1418,6 +1486,7 @@ BINOP(Add)
 BINOP(Sub)
 UNOP(Minus)
 BINOP(Mul)
+BINOP(Mulh)
 DIVOP(Quot)
 DIVOP(DivMod)
 DIVOP(Div)
@@ -1435,7 +1504,7 @@ BINOP(Cmp)
 UNOP(Conv)
 UNOP(Cast)
 
-int get_Conv_strict(ir_node *node) {
+int get_Conv_strict(const ir_node *node) {
        assert(node->op == op_Conv);
        return node->attr.conv.strict;
 }
@@ -1448,6 +1517,7 @@ void set_Conv_strict(ir_node *node, int strict_flag) {
 ir_type *
 get_Cast_type(ir_node *node) {
        assert(node->op == op_Cast);
+       node->attr.cast.totype = skip_tid(node->attr.cast.totype);
        return node->attr.cast.totype;
 }
 
@@ -1465,9 +1535,8 @@ set_Cast_type(ir_node *node, ir_type *to_tp) {
 int is_Cast_upcast(ir_node *node) {
        ir_type *totype   = get_Cast_type(node);
        ir_type *fromtype = get_irn_typeinfo_type(get_Cast_op(node));
-       ir_graph *myirg = get_irn_irg(node);
 
-       assert(get_irg_typeinfo_state(myirg) == ir_typeinfo_consistent);
+       assert(get_irg_typeinfo_state(get_irn_irg(node)) == ir_typeinfo_consistent);
        assert(fromtype);
 
        while (is_Pointer_type(totype) && is_Pointer_type(fromtype)) {
@@ -1554,19 +1623,9 @@ set_binop_right(ir_node *node, ir_node *right) {
        set_irn_n(node, node->op->op_index + 1, right);
 }
 
-int is_Phi(const ir_node *n) {
-       ir_op *op;
-
-       assert(n);
-       op = get_irn_op(n);
-
-       if (op == op_Filter) return get_interprocedural_view();
-
-       if (op == op_Phi)
-               return ((get_irg_phase_state(get_irn_irg(n)) !=  phase_building) ||
-                       (get_irn_arity(n) > 0));
-
-       return 0;
+int
+(is_Phi)(const ir_node *n) {
+       return _is_Phi(n);
 }
 
 int is_Phi0(const ir_node *n) {
@@ -1680,6 +1739,18 @@ set_Load_volatility(ir_node *node, ir_volatility volatility) {
        node->attr.load.volatility = volatility;
 }
 
+ir_align
+get_Load_align(ir_node *node) {
+       assert(node->op == op_Load);
+       return node->attr.load.aligned;
+}
+
+void
+set_Load_align(ir_node *node, ir_align align) {
+       assert(node->op == op_Load);
+       node->attr.load.aligned = align;
+}
+
 
 ir_node *
 get_Store_mem(ir_node *node) {
@@ -1729,6 +1800,18 @@ set_Store_volatility(ir_node *node, ir_volatility volatility) {
        node->attr.store.volatility = volatility;
 }
 
+ir_align
+get_Store_align(ir_node *node) {
+       assert(node->op == op_Store);
+       return node->attr.store.aligned;
+}
+
+void
+set_Store_align(ir_node *node, ir_align align) {
+       assert(node->op == op_Store);
+       node->attr.store.aligned = align;
+}
+
 
 ir_node *
 get_Alloc_mem(ir_node *node) {
@@ -1915,16 +1998,6 @@ set_Proj_pred(ir_node *node, ir_node *pred) {
        set_irn_n(node, 0, pred);
 }
 
-long get_VProj_proj(const ir_node *node)
-{
-       return node->attr.proj;
-}
-
-void set_VProj_proj(ir_node *node, long value)
-{
-       node->attr.proj = value;
-}
-
 long
 get_Proj_proj(const ir_node *node) {
        assert(is_Proj(node));
@@ -2005,17 +2078,16 @@ void set_Confirm_bound(ir_node *node, ir_node *bound) {
        set_irn_n(node, 0, bound);
 }
 
-pn_Cmp get_Confirm_cmp(ir_node *node) {
+pn_Cmp get_Confirm_cmp(const ir_node *node) {
        assert(node->op == op_Confirm);
-       return node->attr.confirm_cmp;
+       return node->attr.confirm.cmp;
 }
 
 void set_Confirm_cmp(ir_node *node, pn_Cmp cmp) {
        assert(node->op == op_Confirm);
-       node->attr.confirm_cmp = cmp;
+       node->attr.confirm.cmp = cmp;
 }
 
-
 ir_node *
 get_Filter_pred(ir_node *node) {
        assert(node->op == op_Filter);
@@ -2133,30 +2205,26 @@ void set_Mux_true(ir_node *node, ir_node *ir_true) {
 
 /* Psi support */
 ir_node *get_Psi_cond(ir_node *node, int pos) {
-       int num_conds = get_Psi_n_conds(node);
        assert(node->op == op_Psi);
-       assert(pos < num_conds);
+       assert(pos < get_Psi_n_conds(node));
        return get_irn_n(node, 2 * pos);
 }
 
 void set_Psi_cond(ir_node *node, int pos, ir_node *cond) {
-       int num_conds = get_Psi_n_conds(node);
        assert(node->op == op_Psi);
-       assert(pos < num_conds);
+       assert(pos < get_Psi_n_conds(node));
        set_irn_n(node, 2 * pos, cond);
 }
 
 ir_node *get_Psi_val(ir_node *node, int pos) {
-       int num_vals = get_Psi_n_conds(node);
        assert(node->op == op_Psi);
-       assert(pos < num_vals);
+       assert(pos < get_Psi_n_conds(node));
        return get_irn_n(node, 2 * pos + 1);
 }
 
 void set_Psi_val(ir_node *node, int pos, ir_node *val) {
-       int num_vals = get_Psi_n_conds(node);
        assert(node->op == op_Psi);
-       assert(pos < num_vals);
+       assert(pos < get_Psi_n_conds(node));
        set_irn_n(node, 2 * pos + 1, val);
 }
 
@@ -2337,9 +2405,15 @@ void set_Pin_op(ir_node *pin, ir_node *node) {
 }
 
 /* Return the assembler text of an ASM pseudo node. */
-const char *get_ASM_text(const ir_node *node) {
+ident *get_ASM_text(const ir_node *node) {
+       assert(node->op == op_ASM);
+       return node->attr.assem.asm_text;
+}
+
+/* Return the number of input constraints for an ASM node. */
+int get_ASM_n_input_constraints(const ir_node *node) {
        assert(node->op == op_ASM);
-       return get_id_str(node->attr.assem.asm_text);
+       return ARR_LEN(node->attr.assem.inputs);
 }
 
 /* Return the input constraints for an ASM node. This is a flexible array. */
@@ -2348,12 +2422,30 @@ const ir_asm_constraint *get_ASM_input_constraints(const ir_node *node) {
        return node->attr.assem.inputs;
 }
 
-/** Return the output constraints for an ASM node. This is a flexible array. */
+/* Return the number of output constraints for an ASM node.  */
+int get_ASM_n_output_constraints(const ir_node *node) {
+       assert(node->op == op_ASM);
+       return ARR_LEN(node->attr.assem.outputs);
+}
+
+/* Return the output constraints for an ASM node. */
 const ir_asm_constraint *get_ASM_output_constraints(const ir_node *node) {
        assert(node->op == op_ASM);
        return node->attr.assem.outputs;
 }
 
+/* Return the number of clobbered registers for an ASM node.  */
+int get_ASM_n_clobbers(const ir_node *node) {
+       assert(node->op == op_ASM);
+       return ARR_LEN(node->attr.assem.clobber);
+}
+
+/* Return the list of clobbered registers for an ASM node. */
+ident **get_ASM_clobbers(const ir_node *node) {
+       assert(node->op == op_ASM);
+       return node->attr.assem.clobber;
+}
+
 /* returns the graph of a node */
 ir_graph *
 get_irn_irg(const ir_node *node) {
@@ -2515,6 +2607,11 @@ int
        return _is_NoMem(node);
 }
 
+int
+(is_Minus)(const ir_node *node) {
+       return _is_Minus(node);
+}
+
 int
 (is_Mod)(const ir_node *node) {
        return _is_Mod(node);
@@ -2540,11 +2637,61 @@ int
        return _is_Add(node);
 }
 
+int
+(is_And)(const ir_node *node) {
+       return _is_And(node);
+}
+
+int
+(is_Or)(const ir_node *node) {
+       return _is_Or(node);
+}
+
+int
+(is_Eor)(const ir_node *node) {
+       return _is_Eor(node);
+}
+
 int
 (is_Sub)(const ir_node *node) {
        return _is_Sub(node);
 }
 
+int
+(is_Shl)(const ir_node *node) {
+       return _is_Shl(node);
+}
+
+int
+(is_Shr)(const ir_node *node) {
+       return _is_Shr(node);
+}
+
+int
+(is_Shrs)(const ir_node *node) {
+       return _is_Shrs(node);
+}
+
+int
+(is_Rot)(const ir_node *node) {
+       return _is_Rot(node);
+}
+
+int
+(is_Not)(const ir_node *node) {
+       return _is_Not(node);
+}
+
+int
+(is_Psi)(const ir_node *node) {
+       return _is_Psi(node);
+}
+
+int
+(is_Tuple)(const ir_node *node) {
+       return _is_Tuple(node);
+}
+
 int
 (is_Start)(const ir_node *node) {
   return _is_Start(node);
@@ -2565,6 +2712,16 @@ int
        return _is_Conv(node);
 }
 
+int
+(is_strictConv)(const ir_node *node) {
+       return _is_strictConv(node);
+}
+
+int
+(is_Cast)(const ir_node *node) {
+       return _is_Cast(node);
+}
+
 int
 (is_no_Block)(const ir_node *node) {
        return _is_no_Block(node);
@@ -2683,7 +2840,7 @@ int
 }
 
 int
-is_Proj(const ir_node *node) {
+(is_Proj)(const ir_node *node) {
        assert(node);
        return node->op == op_Proj ||
               (!get_interprocedural_view() && node->op == op_Filter);
@@ -2722,7 +2879,8 @@ ir_node *get_fragile_op_mem(ir_node *node) {
        case iro_Store :
        case iro_Alloc :
        case iro_Bound :
-               return get_irn_n(node, 0);
+       case iro_CopyB :
+               return get_irn_n(node, pn_Generic_M_regular);
        case iro_Bad   :
        case iro_Unknown:
                return node;
@@ -2826,6 +2984,7 @@ void (set_Cond_jmp_pred)(ir_node *cond, cond_jmp_predicate pred) {
 
 /** the get_type operation must be always implemented and return a firm type */
 static ir_type *get_Default_type(ir_node *n) {
+       (void) n;
        return get_unknown_type();
 }
 
@@ -2863,6 +3022,7 @@ static ir_entity *get_SymConst_attr_entity(ir_node *self) {
 
 /** the get_type_attr operation must be always implemented */
 static ir_type *get_Null_type(ir_node *n) {
+       (void) n;
        return firm_unknown_type;
 }
 
@@ -2885,6 +3045,7 @@ ir_op_ops *firm_set_default_get_type_attr(ir_opcode code, ir_op_ops *ops) {
 
 /** the get_entity_attr operation must be always implemented */
 static ir_entity *get_Null_ent(ir_node *n) {
+       (void) n;
        return NULL;
 }
 
@@ -2902,6 +3063,22 @@ ir_op_ops *firm_set_default_get_entity_attr(ir_opcode code, ir_op_ops *ops) {
        return ops;
 }
 
+/* Sets the debug information of a node. */
+void (set_irn_dbg_info)(ir_node *n, dbg_info *db) {
+       _set_irn_dbg_info(n, db);
+}
+
+/**
+ * Returns the debug information of an node.
+ *
+ * @param n   The node.
+ */
+dbg_info *(get_irn_dbg_info)(const ir_node *n) {
+       return _get_irn_dbg_info(n);
+}
+
+
+
 #ifdef DEBUG_libfirm
 void dump_irn(ir_node *n) {
        int i, arity = get_irn_arity(n);
@@ -2920,5 +3097,5 @@ void dump_irn(ir_node *n) {
 }
 
 #else  /* DEBUG_libfirm */
-void dump_irn(ir_node *n) {}
+void dump_irn(ir_node *n) { (void) n; }
 #endif /* DEBUG_libfirm */