Alien-LibJIT

 view release on metacpan or  search on metacpan

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

		return 0;
	}
	return create_dest_note(func, JIT_OP_CALL_FILTER_RETURN, type);
}

/*@
 * @deftypefun int jit_insn_memcpy (jit_function_t @var{func}, jit_value_t @var{dest}, jit_value_t @var{src}, jit_value_t @var{size})
 * Copy the @var{size} bytes of memory at @var{src} to @var{dest}.
 * It is assumed that the source and destination do not overlap.
 * @end deftypefun
@*/
int jit_insn_memcpy
	(jit_function_t func, jit_value_t dest,
	 jit_value_t src, jit_value_t size)
{
	size = jit_insn_convert(func, size, jit_type_nint, 0);
	return apply_ternary(func, JIT_OP_MEMCPY, dest, src, size);
}

/*@
 * @deftypefun int jit_insn_memmove (jit_function_t @var{func}, jit_value_t @var{dest}, jit_value_t @var{src}, jit_value_t @var{size})
 * Copy the @var{size} bytes of memory at @var{src} to @var{dest}.
 * This is save to use if the source and destination overlap.
 * @end deftypefun
@*/
int jit_insn_memmove
	(jit_function_t func, jit_value_t dest,
	 jit_value_t src, jit_value_t size)
{
	size = jit_insn_convert(func, size, jit_type_nint, 0);
	return apply_ternary(func, JIT_OP_MEMMOVE, dest, src, size);
}

/*@
 * @deftypefun int jit_insn_memset (jit_function_t @var{func}, jit_value_t @var{dest}, jit_value_t @var{value}, jit_value_t @var{size})
 * Set the @var{size} bytes at @var{dest} to @var{value}.
 * @end deftypefun
@*/
int jit_insn_memset
	(jit_function_t func, jit_value_t dest,
	 jit_value_t value, jit_value_t size)
{
	value = jit_insn_convert(func, value, jit_type_int, 0);
	size = jit_insn_convert(func, size, jit_type_nint, 0);
	return apply_ternary(func, JIT_OP_MEMSET, dest, value, size);
}

/*@
 * @deftypefun jit_value_t jit_insn_alloca (jit_function_t @var{func}, jit_value_t @var{size})
 * Allocate @var{size} bytes of memory from the stack.
 * @end deftypefun
@*/
jit_value_t jit_insn_alloca(jit_function_t func, jit_value_t size)
{
	/* Make sure that all deferred pops have been done */
	if(!jit_insn_flush_defer_pop(func, 0))
	{
		return 0;
	}

	/* Round the size to the best alignment boundary on this platform */
	size = jit_insn_convert(func, size, jit_type_nuint, 0);
	size = jit_insn_add
		(func, size, jit_value_create_nint_constant
			(func, jit_type_nuint, JIT_BEST_ALIGNMENT - 1));
	size = jit_insn_and
		(func, size, jit_value_create_nint_constant
			(func, jit_type_nuint, ~((jit_nint)(JIT_BEST_ALIGNMENT - 1))));

	/* Allocate "size" bytes of memory from the stack */
	return apply_unary(func, JIT_OP_ALLOCA, size, jit_type_void_ptr);
}

/*@
 * @deftypefun int jit_insn_move_blocks_to_end (jit_function_t @var{func}, jit_label_t @var{from_label}, jit_label_t @var{to_label})
 * Move all of the blocks between @var{from_label} (inclusive) and
 * @var{to_label} (exclusive) to the end of the current function.
 * This is typically used to move the expression in a @code{while}
 * loop to the end of the body, where it can be executed more
 * efficiently.
 * @end deftypefun
@*/
int jit_insn_move_blocks_to_end
	(jit_function_t func, jit_label_t from_label, jit_label_t to_label)
{
	jit_block_t first, last, block;

	/* Make sure that deferred stack pops are flushed */
	if(!jit_insn_flush_defer_pop(func, 0))
	{
		return 0;
	}

	/* Find the first block that needs to be moved */
	first = jit_block_from_label(func, from_label);
	if(!first)
	{
		return 0;
	}

	/* Find the last block that needs to be moved */
	last = jit_block_from_label(func, to_label);
	if(!last)
	{
		return 0;
	}

	/* Sanity check -- the last block has to be after the first */
	for(block = first->next; block != last; block = block->next)
	{
		if (!block) {
			return 0;
		}
	}

	/* The last block is excluded from the blocks to move */
	block = last->prev;

	/* Move the blocks to the end */
	_jit_block_detach(first, block);
	_jit_block_attach_before(func->builder->exit_block, first, block);



( run in 0.692 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )