blob: 48725c7399dcd47bedca5a94cdfd050df74f1da4 [file] [log] [blame]
Joe Abbeyba3e9012013-02-12 11:45:22 +00001==============================================
2How To Use Attributes
3==============================================
4
5.. contents::
6 :local:
7
8Introduction
9============
10
11Attributes in LLVM have changed in some fundamental ways. It was necessary to do
12this to support expanding the attributes to encompass more than a handful of
13attributes --- e.g. command line options. The old way of handling attributes
14consisted of representing them as a bit mask of values. This bit mask was stored
15in a "list" structure that was reference counted. The advantage of this was that
16attributes could be manipulated with 'or's and 'and's. The disadvantage of this
17was that there was limited room for expansion, and virtually no support for
18attribute-value pairs other than alignment.
19
20In the new scheme, an Attribute object represents a single attribute that's
21uniqued. You use the "Attribute::get" methods to create a new Attribute
22object. An attribute can be a single "enum" value (the enum being the
23Attribute::AttrKind enum), a string representing a target-dependent attribute,
24or an attribute-value pair. Some examples:
25
26* Target-independent:   noinline, zext
27* Target-dependent:     "no-sse", "thumb2"
28* Attribute-value pair: "cpu" = "cortex-a8", align = 4
29
30Note: for an attribute value pair, we expect a target-dependent attribute to
31have a string for the value.
32
33Attribute
34=========
35An Attribute object is designed to be passed around by value.
36
37Because attributes are no longer represented as a bit mask, you will need to
38convert any code which does treat them as a bit mask to use the new query
39methods on the Attribute class.
40
41AttributeSet
42============
43
44The next class is the AttributeSet class. This replaces the old AttributeList
45class. The AttributeSet stores a collection of Attribute objects for each kind
46of object that may have an attribute associated with it: the function as a
47whole, the return type, or the function's parameters. A function's attributes
48are at index "AttributeSet::FunctionIndex"; the return type's attributes are at
49index "AttributeSet::ReturnIndex"; and the function's parameters' attributes are
50at indices 1, ..., n (where 'n' is the number of parameters). Most methods on
51the AttributeSet class take an index parameter.
52
53An AttributeSet is also a uniqued and immutable object. You create an
54AttributeSet through the "AttributeSet::get" methods. You can add and remove
55attributes, which result in the creation of a new AttributeSet.
56
57An AttributeSet object is designed to be passed around by value.
58
59Note: It is advised that you do *not* use the AttributeSet "Introspection"
60methods (e.g. 'Raw', 'getRawPointer', etc.). These methods break encapsulation,
61and may be removed in a future release (i.e. 4.0).
62
63AttrBuilder
64================
65
66Lastly, we have a 'builder' class to help create the AttributeSet object without
67having to create several different intermediate uniqued AttributeSet
68objects. The AttrBuilder class allows you to add and remove attributes at
69will. The attributes won't be uniqued until you call the appropriate
70"AttributeSet::get" method.
71
72An AttrBuilder object is *not* designed to be passed around by value. It should
73be passed by reference.
74
75Note: It is advised that you do *not* use the "AttrBuilder::addRawValue()"
76method or the "AttrBuilder(uint64_t Val)" c'tor. These are for backwards
77compatibility and may be removed in a future release (i.e. 4.0).
78
79And that's basically it! A lot of functionality is hidden behind these classes,
80but the interfaces are pretty straight forward.