Skip to content

Commit 96efdd6

Browse files
committedJun 14, 2016
IR: Introduce local_unnamed_addr attribute.
If a local_unnamed_addr attribute is attached to a global, the address is known to be insignificant within the module. It is distinct from the existing unnamed_addr attribute in that it only describes a local property of the module rather than a global property of the symbol. This attribute is intended to be used by the code generator and LTO to allow the linker to decide whether the global needs to be in the symbol table. It is possible to exclude a global from the symbol table if three things are true: - This attribute is present on every instance of the global (which means that the normal rule that the global must have a unique address can be broken without being observable by the program by performing comparisons against the global's address) - The global has linkonce_odr linkage (which means that each linkage unit must have its own copy of the global if it requires one, and the copy in each linkage unit must be the same) - It is a constant or a function (which means that the program cannot observe that the unique-address rule has been broken by writing to the global) Although this attribute could in principle be computed from the module contents, LTO clients (i.e. linkers) will normally need to be able to compute this property as part of symbol resolution, and it would be inefficient to materialize every module just to compute it. See: http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160509/356401.html http://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20160516/356738.html for earlier discussion. Part of the fix for PR27553. Differential Revision: http://reviews.llvm.org/D20348 llvm-svn: 272709
1 parent 1dc9fd3 commit 96efdd6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+403
-295
lines changed
 

‎llvm/docs/BitCodeFormat.rst

+12-6
Original file line numberDiff line numberDiff line change
@@ -731,8 +731,14 @@ global variable. The operand fields are:
731731
* ``initialexec``: code 3
732732
* ``localexec``: code 4
733733

734-
* *unnamed_addr*: If present and non-zero, indicates that the variable has
735-
``unnamed_addr``
734+
.. _bcunnamedaddr:
735+
736+
* *unnamed_addr*: If present, an encoding of the ``unnamed_addr`` attribute of this
737+
variable:
738+
739+
* not ``unnamed_addr``: code 0
740+
* ``unnamed_addr``: code 1
741+
* ``local_unnamed_addr``: code 2
736742

737743
.. _bcdllstorageclass:
738744

@@ -791,8 +797,8 @@ function. The operand fields are:
791797
* *gc*: If present and nonzero, the 1-based garbage collector index in the table
792798
of `MODULE_CODE_GCNAME`_ entries.
793799

794-
* *unnamed_addr*: If present and non-zero, indicates that the function has
795-
``unnamed_addr``
800+
* *unnamed_addr*: If present, an encoding of the
801+
:ref:`unnamed_addr<bcunnamedaddr>` attribute of this function
796802

797803
* *prologuedata*: If non-zero, the value index of the prologue data for this function,
798804
plus 1.
@@ -830,8 +836,8 @@ fields are
830836
* *threadlocal*: If present, an encoding of the
831837
:ref:`thread local property<bcthreadlocal>` of the alias
832838

833-
* *unnamed_addr*: If present and non-zero, indicates that the alias has
834-
``unnamed_addr``
839+
* *unnamed_addr*: If present, an encoding of the
840+
:ref:`unnamed_addr<bcunnamedaddr>` attribute of this alias
835841

836842
MODULE_CODE_PURGEVALS Record
837843
^^^^^^^^^^^^^^^^^^^^^^^^^^^^

‎llvm/docs/LangRef.rst

+23-13
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,9 @@ initializer. Note that a constant with significant address *can* be
589589
merged with a ``unnamed_addr`` constant, the result being a constant
590590
whose address is significant.
591591

592+
If the ``local_unnamed_addr`` attribute is given, the address is known to
593+
not be significant within the module.
594+
592595
A global variable may be declared to reside in a target-specific
593596
numbered address space. For targets that support them, address spaces
594597
may affect how optimizations are performed and/or what target
@@ -628,7 +631,8 @@ Variables and aliases can have a
628631
Syntax::
629632

630633
@<GlobalVarName> = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal]
631-
[unnamed_addr] [AddrSpace] [ExternallyInitialized]
634+
[(unnamed_addr|local_unnamed_addr)] [AddrSpace]
635+
[ExternallyInitialized]
632636
<global | constant> <Type> [<InitializerConstant>]
633637
[, section "name"] [, comdat [($name)]]
634638
[, align <Alignment>] (, !name !N)*
@@ -675,14 +679,14 @@ an optional list of attached :ref:`metadata <metadata>`,
675679
an opening curly brace, a list of basic blocks, and a closing curly brace.
676680

677681
LLVM function declarations consist of the "``declare``" keyword, an
678-
optional :ref:`linkage type <linkage>`, an optional :ref:`visibility
679-
style <visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`,
680-
an optional :ref:`calling convention <callingconv>`,
681-
an optional ``unnamed_addr`` attribute, a return type, an optional
682-
:ref:`parameter attribute <paramattrs>` for the return type, a function
683-
name, a possibly empty list of arguments, an optional alignment, an optional
684-
:ref:`garbage collector name <gc>`, an optional :ref:`prefix <prefixdata>`,
685-
and an optional :ref:`prologue <prologuedata>`.
682+
optional :ref:`linkage type <linkage>`, an optional :ref:`visibility style
683+
<visibility>`, an optional :ref:`DLL storage class <dllstorageclass>`, an
684+
optional :ref:`calling convention <callingconv>`, an optional ``unnamed_addr``
685+
or ``local_unnamed_addr`` attribute, a return type, an optional :ref:`parameter
686+
attribute <paramattrs>` for the return type, a function name, a possibly
687+
empty list of arguments, an optional alignment, an optional :ref:`garbage
688+
collector name <gc>`, an optional :ref:`prefix <prefixdata>`, and an optional
689+
:ref:`prologue <prologuedata>`.
686690

687691
A function definition contains a list of basic blocks, forming the CFG (Control
688692
Flow Graph) for the function. Each basic block may optionally start with a label
@@ -713,14 +717,17 @@ alignment. All alignments must be a power of 2.
713717
If the ``unnamed_addr`` attribute is given, the address is known to not
714718
be significant and two identical functions can be merged.
715719

720+
If the ``local_unnamed_addr`` attribute is given, the address is known to
721+
not be significant within the module.
722+
716723
Syntax::
717724

718725
define [linkage] [visibility] [DLLStorageClass]
719726
[cconv] [ret attrs]
720727
<ResultType> @<FunctionName> ([argument list])
721-
[unnamed_addr] [fn Attrs] [section "name"] [comdat [($name)]]
722-
[align N] [gc] [prefix Constant] [prologue Constant]
723-
[personality Constant] (!name !N)* { ... }
728+
[(unnamed_addr|local_unnamed_addr)] [fn Attrs] [section "name"]
729+
[comdat [($name)]] [align N] [gc] [prefix Constant]
730+
[prologue Constant] [personality Constant] (!name !N)* { ... }
724731

725732
The argument list is a comma separated sequence of arguments where each
726733
argument is of the following form:
@@ -747,7 +754,7 @@ Aliases may have an optional :ref:`linkage type <linkage>`, an optional
747754

748755
Syntax::
749756

750-
@<Name> = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal] [unnamed_addr] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
757+
@<Name> = [Linkage] [Visibility] [DLLStorageClass] [ThreadLocal] [(unnamed_addr|local_unnamed_addr)] alias <AliaseeTy>, <AliaseeTy>* @<Aliasee>
751758

752759
The linkage must be one of ``private``, ``internal``, ``linkonce``, ``weak``,
753760
``linkonce_odr``, ``weak_odr``, ``external``. Note that some system linkers
@@ -757,6 +764,9 @@ Aliases that are not ``unnamed_addr`` are guaranteed to have the same address as
757764
the aliasee expression. ``unnamed_addr`` ones are only guaranteed to point
758765
to the same content.
759766

767+
If the ``local_unnamed_addr`` attribute is given, the address is known to
768+
not be significant within the module.
769+
760770
Since aliases are only a second name, some restrictions apply, of which
761771
some can only be checked when producing an object file:
762772

0 commit comments

Comments
 (0)
Please sign in to comment.