Beispiel #1
0
VN * IR_GVN::register_bin_vn(IR_TYPE irt, VN const* v0, VN const* v1)
{
	IS_TRUE0(v0 && v1);
	if (is_commutative(irt) && (VN_id(v0) > VN_id(v1))) {
		return register_bin_vn(irt, v1, v0);
	} else if (irt == IR_GT) {
		return register_bin_vn(IR_LT, v1, v0);
	} else if (irt == IR_GE) {
		return register_bin_vn(IR_LE, v1, v0);
	}
	VEC2 * v0_vec = m_irt_vec.get(irt);
	if (v0_vec == NULL) {
		v0_vec = new VEC2();
		m_vec_lst.append_tail((SVECTOR<VN*>*)v0_vec);
		m_irt_vec.set(irt, v0_vec);
	}

	VEC1 * v1_vec = v0_vec->get(VN_id(v0));
	if (v1_vec == NULL) {
		v1_vec = new VEC1();
		m_vec_lst.append_tail((SVECTOR<VN*>*)v1_vec);
		m_vnvec_lst.append_tail(v1_vec);
		v0_vec->set(VN_id(v0), v1_vec);
	}

	VN * res = v1_vec->get(VN_id(v1));
	if (res == NULL) {
		res = new_vn();
		VN_type(res) = VN_OP;
		VN_op(res) = irt;
		v1_vec->set(VN_id(v1), res);
	}
	return res;
}
Beispiel #2
0
static bool try_swap_inputs(ir_node *node)
{
	/* commutative operation, just switch the inputs */
	if (is_commutative(node)) {
		assert(get_amd64_attr_const(node)->op_mode == AMD64_OP_REG_REG);
		/* TODO: support Cmp input swapping */
		ir_node *in0 = get_irn_n(node, 0);
		ir_node *in1 = get_irn_n(node, 1);
		set_irn_n(node, 0, in1);
		set_irn_n(node, 1, in0);
		return true;
	}
	return false;
}
Beispiel #3
0
void tex_tr_attatch(struct tex_tr *f /* father */, 
                    struct tex_tr *s /* son */)
{
	if (f == NULL || s == NULL)
		return;

	if (s->token_id == f->token_id) {
		if (is_commutative(f->token_id)) {
			/* token with associative law */
			list_foreach(&s->tnd.sons, &son_pass, f);
			cp_free(s);
		}
		else {
			goto attach;
		}
	} else {
attach:
		tree_attach(&s->tnd, &f->tnd, NULL, NULL);
	}
}
Beispiel #4
0
	bool process (RuleContext<T>& ctx, FuncRep<T>* func) const override
	{
		if (func->op_.code_ != op_.code_)
		{
			return false;
		}

		auto& args = func->get_args();
		size_t nargs = args.size();
		if (sub_rules_.size() != nargs)
		{
			return false;
		}

		if (is_commutative(func->op_.code_))
		{
			CommCandsT<T> candidates = communtative_rule_match(args, sub_rules_);
			if (candidates.empty()) // we've found no candidates
			{
				return false;
			}
			if (candidates.size() > 1)
			{
				// multiple candidates
				logs::debugf("%d candidates found for func rule",
					candidates.size());
			}
			return ctx.merge(candidates[0].first); // commit transaction
		}
		RuleContext<T> temp_ctx; // acts as a transaction
		for (size_t i = 0; i < nargs; ++i)
		{
			if (false == args[i].arg_->rulify(
				temp_ctx, sub_rules_[i].arg_))
			{
				return false;
			}
			temp_ctx.emplace_edge(func, args[i]);
		}
		return ctx.merge(temp_ctx); // commit transaction
	}
Beispiel #5
0
	VariadicFuncRule (ade::Opcode op, RuleArgsT<T> sub_rules,
		size_t variadic_id) :
		op_(op), sub_rules_(sub_rules), variadic_id_(variadic_id)
	{
		assert(is_commutative(op.code_));
	}