This is an archive of the discontinued LLVM Phabricator instance.

Add alignment argument to the byval attribute (prototype)
Changes PlannedPublic

Authored by chill on Apr 13 2021, 10:41 AM.

Details

Summary

*This is a DRAFT*

Problem statement:

We have up to three relevant alignment properties for a parameter:

  • the alignment of the parameter itself (if it happens to be passed in memory)
  • if it's a pointer, the actual alignment of the pointed to memory (as an optimisation aid)
  • if it's a byval or a byref argument, the minimum alignment of the storage, allocated

for the original argument value (ABI affecting).

For non-pointer arguments alignstack(N) gives stack slot alignment.
For pointer arguments, we retain that use of alignstack(N) and also
have align(M) to give the actual alignment of the contained pointer.

Now when we add byval or byref to the above, there is no attribute
left to give the alignment of the allocated memory. We thought of
using alignstack(N), but that would leave us without a way to
specify the pointer alignment itself.

Proposed solution:

Extend the byval(Ty) attribute to byval(Ty [, Align]) (same for
byref` and preallocated).

(Most of the attributes take zero or one parameters, but there's a
precedent with allocsize(<EltSizeParam>[, <NumEltsParam>]))

So we end up with :

  • align(N) for pointer content
  • stackalign(N) for the minimum alignment for of the actual argument, if it ends up in memory
  • byval(Ty[, N]) and byref(Ty[, N]) for the original argument value

This patch is the prototype implementation, which changes only byval.

Diff Detail