Ejemplo n.º 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;
}
Ejemplo n.º 2
0
static ir_node *get_vtable_ref(ir_type *type)
{
	ir_entity *cls_vtable = oo_get_class_vtable_entity(type);
	if (cls_vtable == NULL)
		return NULL;
	ir_graph *ccode = get_const_code_irg();
	ir_node  *addr  = new_r_Address(ccode, cls_vtable);
	unsigned offset
		= ddispatch_get_vptr_points_to_index() * get_mode_size_bytes(mode_reference);
	ir_mode *offset_mode = get_reference_offset_mode(mode_reference);
	ir_node *cnst  = new_r_Const_long(ccode, offset_mode, offset);
	ir_node *block = get_r_cur_block(ccode);
	ir_node *add   = new_r_Add(block, addr, cnst);
	return add;
}
Ejemplo n.º 3
0
ir_graph *new_const_code_irg(void)
{
	ir_graph *const res = new_r_ir_graph(NULL, 0);
	mature_immBlock(get_irg_end_block(res));

	/* There is no Start node in the const_code_irg */
	set_irg_start(res, new_r_Bad(res, mode_T));
	set_irg_frame(res, new_r_Bad(res, mode_BAD));
	set_irg_args(res, new_r_Bad(res, mode_T));
	set_irg_initial_mem(res, new_r_Bad(res, mode_M));
	set_r_store(res, get_irg_no_mem(res));

	/* Set the visited flag high enough that the blocks will never be
	 * visited. */
	ir_node *const body_block = get_r_cur_block(res);
	set_irn_visited(body_block, -1);
	set_Block_block_visited(body_block, -1);
	ir_node *const start_block = get_irg_start_block(res);
	set_Block_block_visited(start_block, -1);
	set_irn_visited(start_block, -1);

	return res;
}