示例#1
0
static int apply_alternating_path(bipartite_t const *const gr,
                                  int *const matching,
                                  bitset_t *const matched_left,
                                  bitset_t *const matched_right)
{
	bool done_something = false;
	bitset_t *const tmp = bitset_alloca(gr->n_right);

	for (unsigned left = 0; left < gr->n_left; ++left) {
		bitset_t *left_adj = gr->adj[left];
		bitset_copy(tmp, left_adj);

		if (matching[left] >= 0) {
			int old_right = matching[left];

			/* Check of all neighbors of the left node are already matched.
			 * We cannot improve this edge then. */
			if (bitset_contains(left_adj, matched_right))
				continue;

			bitset_andnot(tmp, matched_right);
			unsigned right = bitset_next_set(tmp, 0);
			assert(right != ~0u);

			/* We have to find another left node which has the old right one as
			 * a neighbor. This node must not be part of a matching */
			unsigned i;
			for (i = 0; i < gr->n_left; ++i)
				if (i != left && bitset_is_set(gr->adj[i], old_right) && !bitset_is_set(matched_left, i))
					break;

			/* If no such node can be found, exit. */
			if (i >= gr->n_left)
				continue;

			/* Else, we can improve this edge. */
			matching[left] = right;
			matching[i] = old_right;
			bitset_set(matched_left, i);
			bitset_set(matched_right, right);
			done_something = true;
		} else {
			/* We have to create a new single edge */
			assert(!bitset_is_set(matched_left, left));

			bitset_andnot(tmp, matched_right);
			if (bitset_is_empty(tmp))
				continue;

			unsigned right = bitset_next_set(tmp, 0);
			assert(!bitset_is_set(matched_right, right));
			matching[left] = right;
			bitset_set(matched_left, left);
			bitset_set(matched_right, right);
			done_something = true;
		}
	}

	return done_something;
}
示例#2
0
int has_backedges(const ir_node *n)
{
	bitset_t *ba = get_backarray(n);
	if (ba != NULL) {
		return !bitset_is_empty(ba);
	}
	return 0;
}
示例#3
0
// returns true iff this labelset is empty
static SB_INLINE bool labelset_is_empty(LabelSet *ls) {
    if (ls == 0) return true;
    return bitset_is_empty(*(ls->set));
}