* block_end_with_jump to a block question
@ 2023-06-16 16:56 Li, Yicheng
2023-06-16 17:16 ` David Malcolm
0 siblings, 1 reply; 2+ messages in thread
From: Li, Yicheng @ 2023-06-16 16:56 UTC (permalink / raw)
To: jit
[-- Attachment #1: Type: text/plain, Size: 2940 bytes --]
Hi,
I created a a few blocks using gcc_jit_function_new_block.
While I have a jit function param coming in as “index”.
But the “index” has a type as gcc_jit_lvalue, which cannot be consider as an integer, thus, I cannot do gcc_jit_block_end_with_jump( block, NULL, elem_block[index].
Is there a trick to do this?
Here’s the code.
gcc_jit_lvalue *dst_input = gcc_jit_function_new_local( func, NULL, char_ptr_ptr_type, "dst_input" ),
*src_val = gcc_jit_function_new_local( func, NULL, char_ptr_type, "src_val" ),
*src_loop = gcc_jit_function_new_local( func, NULL, char_ptr_type, "src_loop" ),
*index_val = gcc_jit_function_new_local( func, NULL, int_ptr_type, "index_val" ),
*disp_val = gcc_jit_function_new_local( func, NULL, sizet_ptr_type, "disp_val" ),
*maxdata_val = gcc_jit_function_new_local( func, NULL, sizet_ptr_type, "maxdata_val" );
gcc_jit_block_add_assignment( block, NULL, dst_input, gcc_jit_param_as_rvalue( param[0] ) );
gcc_jit_block_add_assignment( block, NULL, src_val, gcc_jit_param_as_rvalue( param[1] ) );
gcc_jit_block_add_assignment( block, NULL, index_val, gcc_jit_param_as_rvalue( param[2] ) );
gcc_jit_block_add_assignment( block, NULL, disp_val, gcc_jit_param_as_rvalue( param[3] ) );
gcc_jit_block_add_assignment( block, NULL, maxdata_val, gcc_jit_param_as_rvalue( param[4] ) );
gcc_jit_lvalue *dst_val = gcc_jit_context_new_array_access( ctxt, NULL, dst_input,
gcc_jit_context_new_rvalue_from_int( ctxt, int_type, 0 ) ),
*index = gcc_jit_context_new_array_access( ctxt, NULL, index_val,
gcc_jit_context_new_rvalue_from_int( ctxt, int_type, 0 ) ),
*disp = gcc_jit_context_new_array_access( ctxt, NULL, disp_val,
gcc_jit_context_new_rvalue_from_int( ctxt, int_type, 0 ) ),
*maxdata = gcc_jit_context_new_array_access( ctxt, NULL, maxdata_val,
gcc_jit_context_new_rvalue_from_int( ctxt, int_type, 0 ) );
gcc_jit_lvalue *count_val = gcc_jit_function_new_local( func, NULL, int_type, "elem_count" );
gcc_jit_block *elem_block[desc_used],
*elem_exit_block[desc_used];
int blockn = 0,
nelem = 0;
for( int i = 0; i <= desc_used; i++ ){
char block_name[10];
elem_block[nelem] = gcc_jit_function_new_block( func, itoa( blockn++, block_name, 10 ) );
nelem++;
}
gcc_jit_block_end_with_jump( block, NULL, elem_block[index] );
The error from compiler is
error: array subscript is not an integer
1183 | gcc_jit_block_end_with_jump( block, NULL, elem_block[index] );
Thank you
Yicheng Li
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: block_end_with_jump to a block question
2023-06-16 16:56 block_end_with_jump to a block question Li, Yicheng
@ 2023-06-16 17:16 ` David Malcolm
0 siblings, 0 replies; 2+ messages in thread
From: David Malcolm @ 2023-06-16 17:16 UTC (permalink / raw)
To: Li, Yicheng, jit
On Fri, 2023-06-16 at 16:56 +0000, Li, Yicheng via Jit wrote:
> Hi,
>
> I created a a few blocks using gcc_jit_function_new_block.
> While I have a jit function param coming in as “index”.
> But the “index” has a type as gcc_jit_lvalue, which cannot be
> consider as an integer, thus, I cannot do
> gcc_jit_block_end_with_jump( block, NULL, elem_block[index].
> Is there a trick to do this?
Hi
It's not quite clear to me what the code is trying to do...
>
> gcc_jit_lvalue *dst_input = gcc_jit_function_new_local( func, NULL, char_ptr_ptr_type, "dst_input" ),
>
> *src_val = gcc_jit_function_new_local( func, NULL, char_ptr_type, "src_val" ),
>
> *src_loop = gcc_jit_function_new_local( func, NULL, char_ptr_type, "src_loop" ),
>
> *index_val = gcc_jit_function_new_local( func, NULL, int_ptr_type, "index_val" ),
...here you create a local variable called "index_val"...
>
> *disp_val = gcc_jit_function_new_local( func, NULL, sizet_ptr_type, "disp_val" ),
>
> *maxdata_val = gcc_jit_function_new_local( func, NULL, sizet_ptr_type, "maxdata_val" );
>
>
> gcc_jit_block_add_assignment( block, NULL, dst_input, gcc_jit_param_as_rvalue( param[0] ) );
>
> gcc_jit_block_add_assignment( block, NULL, src_val, gcc_jit_param_as_rvalue( param[1] ) );
>
> gcc_jit_block_add_assignment( block, NULL, index_val, gcc_jit_param_as_rvalue( param[2] ) );
...and here you create an assignment equivalent to this C code:
index_val = param[2];
>
> gcc_jit_block_add_assignment( block, NULL, disp_val, gcc_jit_param_as_rvalue( param[3] ) );
>
> gcc_jit_block_add_assignment( block, NULL, maxdata_val, gcc_jit_param_as_rvalue( param[4] ) );
>
>
> gcc_jit_lvalue *dst_val = gcc_jit_context_new_array_access( ctxt, NULL, dst_input,
>
> gcc_jit_context_new_rvalue_from_int( ctxt, int_type, 0 ) ),
>
> *index = gcc_jit_context_new_array_access( ctxt, NULL, index_val,
>
> gcc_jit_context_new_rvalue_from_int( ctxt, int_type, 0 ) ),
"index" here is an array access i.e. you're making an lvalue equivalent
to this C code:
index_val[0]
which is equivalent to:
*index_val
>
> *disp = gcc_jit_context_new_array_access( ctxt, NULL, disp_val,
>
> gcc_jit_context_new_rvalue_from_int( ctxt, int_type, 0 ) ),
>
> *maxdata = gcc_jit_context_new_array_access( ctxt, NULL, maxdata_val,
>
> gcc_jit_context_new_rvalue_from_int( ctxt, int_type, 0 ) );
>
>
> gcc_jit_lvalue *count_val = gcc_jit_function_new_local( func, NULL, int_type, "elem_count" );
>
>
> gcc_jit_block *elem_block[desc_used],
>
> *elem_exit_block[desc_used];
>
> int blockn = 0,
>
> nelem = 0;
>
> for( int i = 0; i <= desc_used; i++ ){
>
> char block_name[10];
>
> elem_block[nelem] = gcc_jit_function_new_block( func, itoa( blockn++, block_name, 10 ) );
>
> nelem++;
>
> }
>
>
> gcc_jit_block_end_with_jump( block, NULL, elem_block[index] );
"index" here is the (gcc_jit_lvalue *) from above, referring to an
lvalue equivalent to "index_val[0]".
Which block do you want to be executed after "block"? Or is this meant
to be a switch statement? If so, look at
https://gcc.gnu.org/onlinedocs/jit/topics/functions.html#c.gcc_jit_block_end_with_switch
>
> The error from compiler is
>
> error: array subscript is not an integer
>
> 1183 | gcc_jit_block_end_with_jump( block, NULL,
> elem_block[index] );
This is looking up an element of the "elem_block" array, and so needs
an integer value, not a (gcc_jit_lvalue *).
Hope this is helpful
Dave
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-06-16 17:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-06-16 16:56 block_end_with_jump to a block question Li, Yicheng
2023-06-16 17:16 ` David Malcolm
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).