a couple struct & alignment questions

All,

I’m using Clang as a frontend for C compilation. I have some tweaks I need to make to the produced IR. I’m not sure if there’s a way to get what I want via CLI options. I’d like to be able to make them without making any changes to Clang itself.

  1. Is there a way to force Clang to respect a struct being passed by value in the source (either as arguments or the return value from a function) and not converted to pointers in & out?

I think, roughly, what I want is to be able to “disable” Clang’s use of ABIArgInfo’s Kind’s Indirect & Expand.

  1. Is there a way to make Clang only perform aligned loads & stores?

Thanks,
Matthew

All,

I’m using Clang as a frontend for C compilation. I have some tweaks I need to make to the produced IR. I’m not sure if there’s a way to get what I want via CLI options. I’d like to be able to make them without making any changes to Clang itself.

  1. Is there a way to force Clang to respect a struct being passed by value in the source (either as arguments or the return value from a function) and not converted to pointers in & out?

I think, roughly, what I want is to be able to “disable” Clang’s use of ABIArgInfo’s Kind’s Indirect & Expand.

  1. Is there a way to make Clang only perform aligned loads & stores?

Thanks,
Matthew

<cross posted form cfe-users, cfe-dev>

All,

I’m using Clang as a frontend for C compilation. I have some tweaks I need to make to the produced IR. I’m not sure if there’s a way to get what I want via CLI options. I’d like to be able to make them without making any changes to Clang itself.

  1. Is there a way to force Clang to respect a struct being passed by value in the source (either as arguments or the return value from a function) and not converted to pointers in & out?

I think, roughly, what I want is to be able to “disable” Clang’s use of ABIArgInfo’s Kind’s Indirect & Expand.

  1. Is there a way to make Clang only perform aligned loads & stores?

Thanks,
Matthew

1. Is there a way to force Clang to respect a struct being passed by value
in the source (either as arguments or the return value from a function) and
not converted to pointers in & out?

I think, roughly, what I want is to be able to "disable" Clang's use of
ABIArgInfo's Kind's Indirect & Expand.

What exactly do you want clang to do? Do you want it to pass the value as
an LLVM first class aggregate, or to use a pointer with the byval attribute?

Either way, there is no flag to do this. You would have to modify Clang.

First, this would break all C++, which may not matter to you.

Second, your code would probably be ABI incompatible with all other code.

2. Is there a way to make Clang only perform aligned loads & stores?

Are you asking if it's possible to force the alignment of loads and stores
up to the natural alignment of the storage type? Clang will already add
alignment annotations to loads and stores as required by the language. It
only leaves them off in cases where it knows the alignment is lost, like
packed structs or explicitly underaligned types.

1. Is there a way to force Clang to respect a struct being passed by
value in the source (either as arguments or the return value from a
function) and not converted to pointers in & out?

I think, roughly, what I want is to be able to "disable" Clang's use of
ABIArgInfo's Kind's Indirect & Expand.

What exactly do you want clang to do? Do you want it to pass the value as
an LLVM first class aggregate, or to use a pointer with the byval attribute?

Pass the value as an LLVM first class aggregate.

Either way, there is no flag to do this. You would have to modify Clang.

First, this would break all C++, which may not matter to you.

How/what would this cause to break in C++?

Second, your code would probably be ABI incompatible with all other code.

I kind of assumed this would happen. I'm not too concerned because I have
control over what is & isn't compiled in this way & can do the necessary
ABI conversions.

2. Is there a way to make Clang only perform aligned loads & stores?

Are you asking if it's possible to force the alignment of loads and stores
up to the natural alignment of the storage type? Clang will already add
alignment annotations to loads and stores as required by the language. It
only leaves them off in cases where it knows the alignment is lost, like
packed structs or explicitly underaligned types.

That is what I'm asking.

Thanks.