Alignment not supported?
David Malcolm
dmalcolm@redhat.com
Sun Jan 1 00:00:00 GMT 2017
On Sat, 2017-03-25 at 23:05 +0900, ì ì¸ë°°(Inbae Jeong) wrote:
> Sorry for being too short. It's JIT mailing list so I thought
> everyone
> would expect it to be related to gccjit.
>
> I'm writing a small JITed interpreter and trying to call an external
> C
> function (actually it is an external "C" C++ function) of which one
> of
> the parameters is a struct containing an aligned member variable.
>
> To make a struct type with gccjit, it will be somewhat like this:
>
> struct my_arg {
> int a;
> alignas(32) int b;
> };
>
> 1: gcc_jit_type *int_type = gcc_jit_context_get_type(ctxt,
> GCC_JIT_TYPE_INT)
> 2: gcc_jit_field *field_a = gcc_jit_context_new_field(ctxt, NULL,
> int_type, "a");
> 3: gcc_jit_field *field_b = gcc_jit_context_new_field(ctxt, NULL,
> int_type, "b"); // How do I specify the alignment?
> 4: gcc_jit_field *fields[2] = {field_a, field_b};
> 5: gcc_jit_struct *my_arg = gcc_jit_context_new_struct_type(ctxt,
> NULL, "my_arg", 2, fields);
>
>
> Maybe the alignment should be specified in line 3 or a new int type
> has to be made with alignment specification, if supported. However I
> don't see anything about alignment in the gccjit manual.
I don't think that there's currently a way to do this from libgccjit.
My first thought was that we could add a way to expose attributes on types from the API, something like:
extern gcc_jit_type *
gcc_jit_type_add_attribute (gcc_jit_type *type,
const char *attribute_name,
/* some extra params */ );
but it's not clear to me what those extra params should look like here.
It could be variadic, but variadic functions make for an error-prone API that's easy to crash, and they're a pain to deal with in language bindings.
Maybe:
extern gcc_jit_type *
gcc_jit_type_add_attribute_int (gcc_jit_type *type,
const char *attribute_name,
int attr_param);
(perhaps adding other suffixes for other type signatures; this is a C API, so there we can't use overloads; the C++ bindings could use them, though).
Alternatively, we could have a special-case entrypoint:
extern gcc_jit_type *
gcc_jit_type_set_alignment (gcc_jit_type *type,
int alignment);
and hide the fact that it's an attribute internally.
I'm not yet sure which approach I prefer (and maybe I need to poke at this from the implementation side to see what's implementable).
What other attributes might people want to use? Thoughts?
Dave
More information about the Jit
mailing list