[LLVMdev] structs get decomposed when shouldn't

Juhasz David juhda at inf.elte.hu
Wed May 2 05:12:13 PDT 2012


Hi guys,

Thanks for the replies.

My basic problem was what Tim referred that the backend legalizes
structs into a sequence of MVTs while building the DAG. However, my
situation is not so complicated here than the example you wrote. Values
can't be split between registers and memory according to Tilera ABI,
and all the arguments need to be passed one after the other as they
come in the signature of the function. So I need only the size and
alignment of the struct to decide what to do with it.

However, the problem was two-fold, as I want to use the backend to
compile C programs through LLVM IR, and clang made some wrong 
modifications to the program because it compiled against x86 ABI, just
as Duncan said. So I made my own clang target for my backend, and found
out a working solution for the problem of broken up structs.

As I wrote, byval is a viable workaround for me. When a struct goes into
the argument area of the caller, callee simply grabs the address. When
the struct fits in registers, the caller copies it to its own stack
frame and use that address.

As for returning a struct, I checked out what other clang targets
generate in such a case. Eventually, the solution is to bitcast structs
to appropriate integer types when returning them, so preventing LLVM
from hacking anything inside structs. It's not a problem to split a
returning struct into register-size parts because there is only one
returning value anyway. The important thing was for me to keep the
content of the struct padded and aligned.

David



More information about the llvm-dev mailing list