[LLVMdev] Argument Lowering

Tim Northover t.p.northover at gmail.com
Mon Feb 11 23:50:51 PST 2013


Hi Hal,

> Can anyone explain why LLVM can't do it?  I've read vague hints of, "not
> all the information is there," but I'd really like to understand this
> better.

The most compelling example I've heard is the x86_64 ABI. It refers to
POD types, unions and structs with non-aligned fields.

I think POD is a red herring because Clang would have to deal with
that anyway and the solution is essentially a byval pointer. Even the
non-aligned fields thing looks similar: any struct with such gets
passed in MEMORY, so a simple front-end test and a byval pointer
should work.

Unions are a much bigger problem. I can't see how a front-end could
decide how to pass them without implementing the given rules itself
(some unions have to have SSE type, some INTEGER, ...). At that stage
you've got quite large duplication between front-end and back-end
anyway. Probably more than is required by the current register
counting front-ends.

I still think the model could work well for ARM-style procedure call
standards (unions are only distinguished by size at the PCS level
there).

> Is there something we can do to make proper argument handling
> possible within LLVM?

At a purely implementation level, the first problem at the moment is
that IR-level types are discarded by the time call lowering happens.
Structures are split up into their constituent fields and those are
all a backend has available for its decisions.

But, because of the above concerns, the only properly viable solution
would probably be to reintroduce union types to LLVM IR. Which is more
complexity for optimisations to handle. I understand they never really
worked properly in the first place.

Cheers

Tim.



More information about the llvm-dev mailing list