2013-02-12 19:26:08 +01:00
|
|
|
=====================
|
2013-02-12 12:45:22 +01:00
|
|
|
How To Use Attributes
|
2013-02-12 19:26:08 +01:00
|
|
|
=====================
|
2013-02-12 12:45:22 +01:00
|
|
|
|
|
|
|
.. contents::
|
2013-02-12 19:26:08 +01:00
|
|
|
:local:
|
2013-02-12 12:45:22 +01:00
|
|
|
|
|
|
|
Introduction
|
|
|
|
============
|
|
|
|
|
2013-02-12 19:26:08 +01:00
|
|
|
Attributes in LLVM have changed in some fundamental ways. It was necessary to
|
|
|
|
do this to support expanding the attributes to encompass more than a handful of
|
|
|
|
attributes --- e.g. command line options. The old way of handling attributes
|
|
|
|
consisted of representing them as a bit mask of values. This bit mask was
|
|
|
|
stored in a "list" structure that was reference counted. The advantage of this
|
|
|
|
was that attributes could be manipulated with 'or's and 'and's. The
|
|
|
|
disadvantage of this was that there was limited room for expansion, and
|
|
|
|
virtually no support for attribute-value pairs other than alignment.
|
|
|
|
|
|
|
|
In the new scheme, an ``Attribute`` object represents a single attribute that's
|
|
|
|
uniqued. You use the ``Attribute::get`` methods to create a new ``Attribute``
|
|
|
|
object. An attribute can be a single "enum" value (the enum being the
|
|
|
|
``Attribute::AttrKind`` enum), a string representing a target-dependent
|
|
|
|
attribute, or an attribute-value pair. Some examples:
|
|
|
|
|
|
|
|
* Target-independent: ``noinline``, ``zext``
|
|
|
|
* Target-dependent: ``"no-sse"``, ``"thumb2"``
|
|
|
|
* Attribute-value pair: ``"cpu" = "cortex-a8"``, ``align = 4``
|
2013-02-12 12:45:22 +01:00
|
|
|
|
|
|
|
Note: for an attribute value pair, we expect a target-dependent attribute to
|
|
|
|
have a string for the value.
|
|
|
|
|
2013-02-12 19:26:08 +01:00
|
|
|
``Attribute``
|
|
|
|
=============
|
|
|
|
An ``Attribute`` object is designed to be passed around by value.
|
2013-02-12 12:45:22 +01:00
|
|
|
|
|
|
|
Because attributes are no longer represented as a bit mask, you will need to
|
|
|
|
convert any code which does treat them as a bit mask to use the new query
|
|
|
|
methods on the Attribute class.
|
|
|
|
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
``AttributeList``
|
2017-03-21 18:05:00 +01:00
|
|
|
=================
|
2013-02-12 12:45:22 +01:00
|
|
|
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
The ``AttributeList`` stores a collection of Attribute objects for each kind of
|
|
|
|
object that may have an attribute associated with it: the function as a whole,
|
|
|
|
the return type, or the function's parameters. A function's attributes are at
|
|
|
|
index ``AttributeList::FunctionIndex``; the return type's attributes are at
|
|
|
|
index ``AttributeList::ReturnIndex``; and the function's parameters' attributes
|
|
|
|
are at indices 1, ..., n (where 'n' is the number of parameters). Most methods
|
|
|
|
on the ``AttributeList`` class take an index parameter.
|
2013-02-12 12:45:22 +01:00
|
|
|
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
An ``AttributeList`` is also a uniqued and immutable object. You create an
|
|
|
|
``AttributeList`` through the ``AttributeList::get`` methods. You can add and
|
|
|
|
remove attributes, which result in the creation of a new ``AttributeList``.
|
2013-02-12 12:45:22 +01:00
|
|
|
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
An ``AttributeList`` object is designed to be passed around by value.
|
2013-02-12 12:45:22 +01:00
|
|
|
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
Note: It is advised that you do *not* use the ``AttributeList`` "introspection"
|
2013-02-12 19:26:08 +01:00
|
|
|
methods (e.g. ``Raw``, ``getRawPointer``, etc.). These methods break
|
|
|
|
encapsulation, and may be removed in a future release (i.e. LLVM 4.0).
|
2013-02-12 12:45:22 +01:00
|
|
|
|
2013-02-12 19:26:08 +01:00
|
|
|
``AttrBuilder``
|
|
|
|
===============
|
2013-02-12 12:45:22 +01:00
|
|
|
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
Lastly, we have a "builder" class to help create the ``AttributeList`` object
|
2013-02-12 19:26:08 +01:00
|
|
|
without having to create several different intermediate uniqued
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
``AttributeList`` objects. The ``AttrBuilder`` class allows you to add and
|
2013-02-12 19:26:08 +01:00
|
|
|
remove attributes at will. The attributes won't be uniqued until you call the
|
Rename AttributeSet to AttributeList
Summary:
This class is a list of AttributeSetNodes corresponding the function
prototype of a call or function declaration. This class used to be
called ParamAttrListPtr, then AttrListPtr, then AttributeSet. It is
typically accessed by parameter and return value index, so
"AttributeList" seems like a more intuitive name.
Rename AttributeSetImpl to AttributeListImpl to follow suit.
It's useful to rename this class so that we can rename AttributeSetNode
to AttributeSet later. AttributeSet is the set of attributes that apply
to a single function, argument, or return value.
Reviewers: sanjoy, javed.absar, chandlerc, pete
Reviewed By: pete
Subscribers: pete, jholewinski, arsenm, dschuff, mehdi_amini, jfb, nhaehnle, sbc100, void, llvm-commits
Differential Revision: https://reviews.llvm.org/D31102
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
appropriate ``AttributeList::get`` method.
|
2013-02-12 12:45:22 +01:00
|
|
|
|
2013-02-12 19:26:08 +01:00
|
|
|
An ``AttrBuilder`` object is *not* designed to be passed around by value. It
|
|
|
|
should be passed by reference.
|
2013-02-12 12:45:22 +01:00
|
|
|
|
2013-02-12 19:26:08 +01:00
|
|
|
Note: It is advised that you do *not* use the ``AttrBuilder::addRawValue()``
|
|
|
|
method or the ``AttrBuilder(uint64_t Val)`` constructor. These are for
|
|
|
|
backwards compatibility and may be removed in a future release (i.e. LLVM 4.0).
|
2013-02-12 12:45:22 +01:00
|
|
|
|
|
|
|
And that's basically it! A lot of functionality is hidden behind these classes,
|
|
|
|
but the interfaces are pretty straight forward.
|
2013-02-12 19:26:08 +01:00
|
|
|
|