Skip to content

[LangRef/DataLayout] Spell out requirements for alignment values #104705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Apr 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions llvm/docs/LangRef.rst
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we say once at the top that all alignment specs must be powers of two etc, rather than repeating it for each use?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did that because size and address spaces requirements are repeated too, but I don't feel like I should be moving them in this PR. (Or should I?)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've moved the repeated sentences to the bottom, next to the other text that talks about alignments.

Original file line number Diff line number Diff line change
Expand Up @@ -3109,8 +3109,7 @@ as follows:
``S<size>``
Specifies the natural alignment of the stack in bits. Alignment
promotion of stack variables is limited to the natural stack
alignment to avoid dynamic stack realignment. The stack alignment
must be a multiple of 8-bits. If omitted, the natural stack
alignment to avoid dynamic stack realignment. If omitted, the natural stack
alignment defaults to "unspecified", which does not prevent any
alignment promotions.
``P<address space>``
Expand All @@ -3136,8 +3135,8 @@ as follows:
Defaults to the default address space of 0.
``p[n]:<size>:<abi>[:<pref>][:<idx>]``
This specifies the *size* of a pointer and its ``<abi>`` and
``<pref>``\erred alignments for address space ``n``. ``<pref>`` is optional
and defaults to ``<abi>``. The fourth parameter ``<idx>`` is the size of the
``<pref>``\erred alignments for address space ``n``.
The fourth parameter ``<idx>`` is the size of the
index that used for address calculation, which must be less than or equal
to the pointer size. If not
specified, the default index size is equal to the pointer size. All sizes
Expand All @@ -3147,23 +3146,21 @@ as follows:
``i<size>:<abi>[:<pref>]``
This specifies the alignment for an integer type of a given bit
``<size>``. The value of ``<size>`` must be in the range [1,2^24).
``<pref>`` is optional and defaults to ``<abi>``.
For ``i8``, the ``<abi>`` value must equal 8,
that is, ``i8`` must be naturally aligned.
``v<size>:<abi>[:<pref>]``
This specifies the alignment for a vector type of a given bit
``<size>``. The value of ``<size>`` must be in the range [1,2^24).
``<pref>`` is optional and defaults to ``<abi>``.
``f<size>:<abi>[:<pref>]``
This specifies the alignment for a floating-point type of a given bit
``<size>``. Only values of ``<size>`` that are supported by the target
will work. 32 (float) and 64 (double) are supported on all targets; 80
or 128 (different flavors of long double) are also supported on some
targets. The value of ``<size>`` must be in the range [1,2^24).
``<pref>`` is optional and defaults to ``<abi>``.
``a:<abi>[:<pref>]``
This specifies the alignment for an object of aggregate type.
``<pref>`` is optional and defaults to ``<abi>``.
In addition to the usual requirements for alignment values,
the value of ``<abi>`` can also be zero, which means one byte alignment.
``F<type><abi>``
This specifies the alignment for function pointers.
The options for ``<type>`` are:
Expand Down Expand Up @@ -3202,6 +3199,9 @@ as follows:
as :ref:`Non-Integral Pointer Type <nointptrtype>` s. The ``0``
address space cannot be specified as non-integral.

Unless explicitly stated otherwise, on every specification that specifies
an alignment, the value of the alignment must be in the range [1,2^16)
and must be a power of two times the width of a byte.
On every specification that takes a ``<abi>:<pref>``, specifying the
``<pref>`` alignment is optional. If omitted, the preceding ``:``
should be omitted too and ``<pref>`` will be equal to ``<abi>``.
Expand Down
Loading