Alien-LibJIT

 view release on metacpan or  search on metacpan

libjit/jit/jit-value.c  view on Meta::CPAN

				}
				jit_type_free(type);
			}
			return func->builder->struct_return;
		}
	}
	return 0;
}

/*@
 * @deftypefun int jit_value_is_temporary (jit_value_t @var{value})
 * Determine if a value is temporary.  i.e. its scope extends
 * over a single block within its function.
 * @end deftypefun
@*/
int jit_value_is_temporary(jit_value_t value)
{
	return value->is_temporary;
}

/*@
 * @deftypefun int jit_value_is_local (jit_value_t @var{value})
 * Determine if a value is local.  i.e. its scope extends
 * over multiple blocks within its function.
 * @end deftypefun
@*/
int jit_value_is_local(jit_value_t value)
{
	return value->is_local;
}

/*@
 * @deftypefun int jit_value_is_constant (jit_value_t @var{value})
 * Determine if a value is a constant.
 * @end deftypefun
@*/
int jit_value_is_constant(jit_value_t value)
{
	return value->is_constant;
}

/*@
 * @deftypefun int jit_value_is_parameter (jit_value_t @var{value})
 * Determine if a value is a function parameter.
 * @end deftypefun
@*/
int jit_value_is_parameter(jit_value_t value)
{
	return value->is_parameter;
}

/*@
 * @deftypefun void jit_value_ref (jit_function_t @var{func}, jit_value_t @var{value})
 * Create a reference to the specified @var{value} from the current
 * block in @var{func}.  This will convert a temporary value into
 * a local value if @var{value} is being referenced from a different
 * block than its original.
 *
 * It is not necessary that @var{func} be the same function as the
 * one where the value was originally created.  It may be a nested
 * function, referring to a local variable in its parent function.
 * @end deftypefun
@*/
void jit_value_ref(jit_function_t func, jit_value_t value)
{
	if(!value || !_jit_function_ensure_builder(func))
	{
		return;
	}
	++(value->usage_count);
	if(value->is_temporary)
	{
		if(value->block->func != func)
		{
			/* Reference from a different function: local and addressable */
			value->is_temporary = 0;
			value->is_local = 1;
			value->is_addressable = 1;

			/* Mark the two functions as not leaves because we will need
			   them to set up proper frame pointers to allow us to access
			   the local variable across the nested function boundary */
			value->block->func->builder->non_leaf = 1;
			func->builder->non_leaf = 1;
		}
		else if(value->block != func->builder->current_block)
		{
			/* Reference from another block in same function: local */
			value->is_temporary = 0;
			value->is_local = 1;
			if(_jit_gen_is_global_candidate(value->type))
			{
				value->global_candidate = 1;
			}
		}
	}
	else if(value->is_local && value->block->func != func)
	{
		/* Convert a previously local value into an addressable one */
		value->is_addressable = 1;
		value->block->func->builder->non_leaf = 1;
		func->builder->non_leaf = 1;
	}
}

void _jit_value_ref_params(jit_function_t func)
{
	unsigned int num_params;
	unsigned int param;
	if(func->builder->param_values)
	{
		num_params = jit_type_num_params(func->signature);
		for(param = 0; param < num_params; ++param)
		{
			jit_value_ref(func, func->builder->param_values[param]);
		}
	}
	jit_value_ref(func, func->builder->struct_return);
	jit_value_ref(func, func->builder->parent_frame);
}

/*@
 * @deftypefun void jit_value_set_volatile (jit_value_t @var{value})
 * Set a flag on a value to indicate that it is volatile.  The contents
 * of the value must always be reloaded from memory, never from a
 * cached register copy.
 * @end deftypefun
@*/
void jit_value_set_volatile(jit_value_t value)
{
	value->is_volatile = 1;
}

/*@
 * @deftypefun int jit_value_is_volatile (jit_value_t @var{value})
 * Determine if a value is volatile.
 * @end deftypefun
@*/
int jit_value_is_volatile(jit_value_t value)
{
	return value->is_volatile;
}

/*@
 * @deftypefun void jit_value_set_addressable (jit_value_t @var{value})
 * Set a flag on a value to indicate that it is addressable.
 * This should be used when you want to take the address of a
 * value (e.g. @code{&variable} in C).  The value is guaranteed
 * to not be stored in a register across a function call.
 * If you refer to a value from a nested function (@code{jit_value_ref}),
 * then the value will be automatically marked as addressable.
 * @end deftypefun
@*/
void jit_value_set_addressable(jit_value_t value)
{
	value->is_addressable = 1;
}

/*@
 * @deftypefun int jit_value_is_addressable (jit_value_t @var{value})
 * Determine if a value is addressable.
 * @end deftypefun
@*/
int jit_value_is_addressable(jit_value_t value)
{
	return value->is_addressable;
}

/*@
 * @deftypefun jit_type_t jit_value_get_type (jit_value_t @var{value})
 * Get the type that is associated with a value.
 * @end deftypefun
@*/
jit_type_t jit_value_get_type(jit_value_t value)
{
	if(value)
	{
		return value->type;
	}



( run in 0.332 second using v1.01-cache-2.11-cpan-3d66aa2751a )