-/** Compares two exception attributes */
-static int node_cmp_exception(const ir_node *a, const ir_node *b)
-{
- const except_attr *ea = &a->attr.except;
- const except_attr *eb = &b->attr.except;
- return ea->pin_state != eb->pin_state;
-}
-
-/** Compares the attributes of two Const nodes. */
-static int node_cmp_attr_Const(const ir_node *a, const ir_node *b)
-{
- return get_Const_tarval(a) != get_Const_tarval(b);
-}
-
-/** Compares the attributes of two Proj nodes. */
-static int node_cmp_attr_Proj(const ir_node *a, const ir_node *b)
-{
- return a->attr.proj.proj != b->attr.proj.proj;
-}
-
-/** Compares the attributes of two Alloc nodes. */
-static int node_cmp_attr_Alloc(const ir_node *a, const ir_node *b)
-{
- const alloc_attr *pa = &a->attr.alloc;
- const alloc_attr *pb = &b->attr.alloc;
- if (pa->where != pb->where || pa->type != pb->type)
- return 1;
- return node_cmp_exception(a, b);
-}
-
-/** Compares the attributes of two Free nodes. */
-static int node_cmp_attr_Free(const ir_node *a, const ir_node *b)
-{
- const free_attr *pa = &a->attr.free;
- const free_attr *pb = &b->attr.free;
- return (pa->where != pb->where) || (pa->type != pb->type);
-}
-
-/** Compares the attributes of two SymConst nodes. */
-static int node_cmp_attr_SymConst(const ir_node *a, const ir_node *b)
-{
- const symconst_attr *pa = &a->attr.symc;
- const symconst_attr *pb = &b->attr.symc;
- return (pa->kind != pb->kind)
- || (pa->sym.type_p != pb->sym.type_p);
-}
-
-/** Compares the attributes of two Call nodes. */
-static int node_cmp_attr_Call(const ir_node *a, const ir_node *b)
-{
- const call_attr *pa = &a->attr.call;
- const call_attr *pb = &b->attr.call;
- if (pa->type != pb->type)
- return 1;
- return node_cmp_exception(a, b);
-}
-
-/** Compares the attributes of two Sel nodes. */
-static int node_cmp_attr_Sel(const ir_node *a, const ir_node *b)
-{
- const ir_entity *a_ent = get_Sel_entity(a);
- const ir_entity *b_ent = get_Sel_entity(b);
- return a_ent != b_ent;
-}
-
-/** Compares the attributes of two Phi nodes. */
-static int node_cmp_attr_Phi(const ir_node *a, const ir_node *b)
-{
- (void) b;
- /* do not CSE Phi-nodes without any inputs when building new graphs */
- if (get_irn_arity(a) == 0 &&
- get_irg_phase_state(get_irn_irg(a)) == phase_building) {
- return 1;
- }
- return 0;
-}
-
-/** Compares the attributes of two Conv nodes. */
-static int node_cmp_attr_Conv(const ir_node *a, const ir_node *b)
-{
- return get_Conv_strict(a) != get_Conv_strict(b);
-}
-
-/** Compares the attributes of two Cast nodes. */
-static int node_cmp_attr_Cast(const ir_node *a, const ir_node *b)
-{
- return get_Cast_type(a) != get_Cast_type(b);
-}
-
-/** Compares the attributes of two Load nodes. */
-static int node_cmp_attr_Load(const ir_node *a, const ir_node *b)
-{
- if (get_Load_volatility(a) == volatility_is_volatile ||
- get_Load_volatility(b) == volatility_is_volatile)
- /* NEVER do CSE on volatile Loads */
- return 1;
- /* do not CSE Loads with different alignment. Be conservative. */
- if (get_Load_unaligned(a) != get_Load_unaligned(b))
- return 1;
- if (get_Load_mode(a) != get_Load_mode(b))
- return 1;
- return node_cmp_exception(a, b);
-}
-
-/** Compares the attributes of two Store nodes. */
-static int node_cmp_attr_Store(const ir_node *a, const ir_node *b)
-{
- /* do not CSE Stores with different alignment. Be conservative. */
- if (get_Store_unaligned(a) != get_Store_unaligned(b))
- return 1;
- /* NEVER do CSE on volatile Stores */
- if (get_Store_volatility(a) == volatility_is_volatile ||
- get_Store_volatility(b) == volatility_is_volatile)
- return 1;
- return node_cmp_exception(a, b);
-}
-
-static int node_cmp_attr_CopyB(const ir_node *a, const ir_node *b)
-{
- if (get_CopyB_type(a) != get_CopyB_type(b))
- return 1;
-
- return node_cmp_exception(a, b);
-}
-
-static int node_cmp_attr_Bound(const ir_node *a, const ir_node *b)
-{
- return node_cmp_exception(a, b);
-}
-
-/** Compares the attributes of two Div nodes. */
-static int node_cmp_attr_Div(const ir_node *a, const ir_node *b)
-{
- const div_attr *ma = &a->attr.div;
- const div_attr *mb = &b->attr.div;
- if (ma->resmode != mb->resmode || ma->no_remainder != mb->no_remainder)
- return 1;
- return node_cmp_exception(a, b);
-}
-
-/** Compares the attributes of two Mod nodes. */
-static int node_cmp_attr_Mod(const ir_node *a, const ir_node *b)
-{
- const mod_attr *ma = &a->attr.mod;
- const mod_attr *mb = &b->attr.mod;
- if (ma->resmode != mb->resmode)
- return 1;
- return node_cmp_exception(a, b);
-}
-
-static int node_cmp_attr_Cmp(const ir_node *a, const ir_node *b)
-{
- const cmp_attr *ma = &a->attr.cmp;
- const cmp_attr *mb = &b->attr.cmp;
- return ma->relation != mb->relation;
-}
-
-/** Compares the attributes of two Confirm nodes. */
-static int node_cmp_attr_Confirm(const ir_node *a, const ir_node *b)
-{
- const confirm_attr *ma = &a->attr.confirm;
- const confirm_attr *mb = &b->attr.confirm;
- return ma->relation != mb->relation;
-}
-
-/** Compares the attributes of two Builtin nodes. */
-static int node_cmp_attr_Builtin(const ir_node *a, const ir_node *b)
-{
- if (get_Builtin_kind(a) != get_Builtin_kind(b))
- return 1;
- if (get_Builtin_type(a) != get_Builtin_type(b))
- return 1;
- return node_cmp_exception(a, b);
-}
-
-/** Compares the attributes of two ASM nodes. */
-static int node_cmp_attr_ASM(const ir_node *a, const ir_node *b)
-{
- size_t n;
- size_t i;
- const ir_asm_constraint *ca;
- const ir_asm_constraint *cb;
- ident **cla, **clb;
-
- if (get_ASM_text(a) != get_ASM_text(b))
- return 1;
-
- /* Should we really check the constraints here? Should be better, but is strange. */
- n = get_ASM_n_input_constraints(a);
- if (n != get_ASM_n_input_constraints(b))
- return 1;
-
- ca = get_ASM_input_constraints(a);
- cb = get_ASM_input_constraints(b);
- for (i = 0; i < n; ++i) {
- if (ca[i].pos != cb[i].pos || ca[i].constraint != cb[i].constraint
- || ca[i].mode != cb[i].mode)
- return 1;
- }
-
- n = get_ASM_n_output_constraints(a);
- if (n != get_ASM_n_output_constraints(b))
- return 1;
-
- ca = get_ASM_output_constraints(a);
- cb = get_ASM_output_constraints(b);
- for (i = 0; i < n; ++i) {
- if (ca[i].pos != cb[i].pos || ca[i].constraint != cb[i].constraint
- || ca[i].mode != cb[i].mode)
- return 1;
- }
-
- n = get_ASM_n_clobbers(a);
- if (n != get_ASM_n_clobbers(b))
- return 1;
-
- cla = get_ASM_clobbers(a);
- clb = get_ASM_clobbers(b);
- for (i = 0; i < n; ++i) {
- if (cla[i] != clb[i])
- return 1;
- }
-
- return node_cmp_exception(a, b);
-}
-
-/** Compares the inexistent attributes of two Dummy nodes. */
-static int node_cmp_attr_Dummy(const ir_node *a, const ir_node *b)
-{
- (void) a;
- (void) b;
- /* Dummy nodes never equal by definition */
- return 1;
-}
-
-static int node_cmp_attr_InstOf(const ir_node *a, const ir_node *b)
-{
- if (get_InstOf_type(a) != get_InstOf_type(b))
- return 1;
- return node_cmp_exception(a, b);
-}
-
-void firm_set_default_node_cmp_attr(ir_opcode code, ir_op_ops *ops)
-{
-#define CASE(a) \
- case iro_##a: \
- ops->node_cmp_attr = node_cmp_attr_##a; \
- break
-
- switch (code) {
- CASE(ASM);
- CASE(Alloc);
- CASE(Bound);
- CASE(Builtin);
- CASE(Call);
- CASE(Cast);
- CASE(Cmp);
- CASE(Confirm);
- CASE(Const);
- CASE(Conv);
- CASE(CopyB);
- CASE(Div);
- CASE(Dummy);
- CASE(Free);
- CASE(InstOf);
- CASE(Load);
- CASE(Mod);
- CASE(Phi);
- CASE(Proj);
- CASE(Sel);
- CASE(Store);
- CASE(SymConst);
- default:
- /* leave NULL */
- break;
- }
-#undef CASE
-}
-