Beispiel #1
0
/**
 * This function returns the last definition of a value.  In case
 * this value was last defined in a previous block, Phi nodes are
 * inserted.  If the part of the firm graph containing the definition
 * is not yet constructed, a dummy Phi node is returned.
 *
 * @param block   the current block
 * @param pos     the value number of the value searched
 * @param mode    the mode of this value (needed for Phi construction)
 */
static ir_node *get_r_value_internal(ir_node *block, int pos, ir_mode *mode)
{
	ir_node *res = block->attr.block.graph_arr[pos];
	if (res != NULL)
		return res;

	/* in a matured block we can immediately determine the phi arguments */
	if (get_Block_matured(block)) {
		ir_graph *const irg   = get_irn_irg(block);
		int       const arity = get_irn_arity(block);
		/* no predecessors: use unknown value */
		if (arity == 0) {
			if (block == get_irg_start_block(irg)) {
				if (default_initialize_local_variable != NULL) {
					ir_node *rem = get_r_cur_block(irg);
					set_r_cur_block(irg, block);
					res = default_initialize_local_variable(irg, mode, pos - 1);
					set_r_cur_block(irg, rem);
				} else {
					res = new_r_Unknown(irg, mode);
				}
			} else {
				goto bad; /* unreachable block, use Bad */
			}
		/* one predecessor just use its value */
		} else if (arity == 1) {
			ir_node *cfgpred = get_Block_cfgpred(block, 0);
			if (is_Bad(cfgpred)) {
bad:
				res = new_r_Bad(irg, mode);
			} else {
				ir_node *cfgpred_block = get_nodes_block(cfgpred);
				res = get_r_value_internal(cfgpred_block, pos, mode);
			}
		} else {
			/* multiple predecessors construct Phi */
			res = new_rd_Phi0(NULL, block, mode, pos);
			/* enter phi0 into our variable value table to break cycles
			 * arising from set_phi_arguments */
			block->attr.block.graph_arr[pos] = res;
			res = set_phi_arguments(res, pos);
		}
	} else {
		/* in case of immature block we have to keep a Phi0 */
		res = new_rd_Phi0(NULL, block, mode, pos);
		/* enqueue phi so we can set arguments once the block matures */
		res->attr.phi.next     = block->attr.block.phis;
		block->attr.block.phis = res;
	}
	block->attr.block.graph_arr[pos] = res;
	return res;
}
Beispiel #2
0
/**
 * Returns backarray if the node can have backedges, else returns
 * NULL.
 *
 * Does not assert whether the backarray is correct -- use
 * very careful!
 */
static bitset_t *mere_get_backarray(const ir_node *n)
{
	switch (get_irn_opcode(n)) {
	case iro_Block:
		if (!get_Block_matured(n))
			return NULL;

		assert(n->attr.block.backedge != NULL);
		return n->attr.block.backedge;
	case iro_Phi:
		assert(n->attr.phi.u.backedge != NULL);
		return n->attr.phi.u.backedge;
	default:
		break;
	}
	return NULL;
}
Beispiel #3
0
void mature_immBlock(ir_node *block)
{
	if (get_Block_matured(block))
		return;

	set_Block_matured(block, 1);

	/* Create final in-array for the block. */
	ir_graph *const irg = get_irn_irg(block);
	if (block->attr.block.dynamic_ins) {
		/* Attach a Bad predecessor if there is no other. This is necessary to
		 * fulfill the invariant that all nodes can be found through reverse
		 * edges from the start block. */
		ir_node             **new_in;
		struct obstack *const obst    = get_irg_obstack(irg);
		size_t                n_preds = ARR_LEN(block->in) - 1;
		if (n_preds == 0) {
			n_preds   = 1;
			new_in    = NEW_ARR_D(ir_node*, obst, 2);
			new_in[0] = NULL;
			new_in[1] = new_r_Bad(irg, mode_X);
		} else {