2017-05-15 21:57:41 +00:00
|
|
|
//===- AttributeImpl.h - Attribute Internals --------------------*- C++ -*-===//
|
2012-09-26 21:07:29 +00:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2012-12-20 21:28:43 +00:00
|
|
|
///
|
|
|
|
/// \file
|
|
|
|
/// \brief This file defines various helper methods and classes used by
|
|
|
|
/// LLVMContextImpl for creating and managing attributes.
|
|
|
|
///
|
2012-09-26 21:07:29 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 16:26:38 +00:00
|
|
|
#ifndef LLVM_LIB_IR_ATTRIBUTEIMPL_H
|
|
|
|
#define LLVM_LIB_IR_ATTRIBUTEIMPL_H
|
2012-09-26 21:07:29 +00:00
|
|
|
|
2016-12-07 22:06:02 +00:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2012-09-26 21:07:29 +00:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2016-12-07 22:06:02 +00:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2013-01-02 11:36:10 +00:00
|
|
|
#include "llvm/IR/Attributes.h"
|
2016-12-07 22:06:02 +00:00
|
|
|
#include "llvm/Support/TrailingObjects.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2016-01-29 22:35:29 +00:00
|
|
|
#include <string>
|
2016-12-07 22:06:02 +00:00
|
|
|
#include <utility>
|
2012-09-26 21:07:29 +00:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2012-12-19 23:55:43 +00:00
|
|
|
class LLVMContext;
|
|
|
|
|
2013-02-05 22:37:24 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
2013-07-11 12:13:16 +00:00
|
|
|
/// \brief This class represents a single, uniqued attribute. That attribute
|
|
|
|
/// could be a single enum, a tuple, or a string.
|
2013-09-11 18:05:11 +00:00
|
|
|
class AttributeImpl : public FoldingSetNode {
|
2013-07-11 12:13:16 +00:00
|
|
|
unsigned char KindID; ///< Holds the AttrEntryKind of the attribute
|
|
|
|
|
2013-02-05 22:37:24 +00:00
|
|
|
protected:
|
|
|
|
enum AttrEntryKind {
|
|
|
|
EnumAttrEntry,
|
2014-07-18 06:51:55 +00:00
|
|
|
IntAttrEntry,
|
2013-02-05 22:37:24 +00:00
|
|
|
StringAttrEntry
|
|
|
|
};
|
|
|
|
|
2013-07-11 12:13:16 +00:00
|
|
|
AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {}
|
2013-01-27 21:38:03 +00:00
|
|
|
|
2012-09-26 21:07:29 +00:00
|
|
|
public:
|
2016-12-07 22:06:02 +00:00
|
|
|
// AttributesImpl is uniqued, these should not be available.
|
|
|
|
AttributeImpl(const AttributeImpl &) = delete;
|
|
|
|
AttributeImpl &operator=(const AttributeImpl &) = delete;
|
|
|
|
|
2013-11-18 09:31:53 +00:00
|
|
|
virtual ~AttributeImpl();
|
|
|
|
|
2013-07-11 12:13:16 +00:00
|
|
|
bool isEnumAttribute() const { return KindID == EnumAttrEntry; }
|
2014-07-18 06:51:55 +00:00
|
|
|
bool isIntAttribute() const { return KindID == IntAttrEntry; }
|
2013-07-11 12:13:16 +00:00
|
|
|
bool isStringAttribute() const { return KindID == StringAttrEntry; }
|
2012-10-08 21:47:17 +00:00
|
|
|
|
2013-02-05 22:37:24 +00:00
|
|
|
bool hasAttribute(Attribute::AttrKind A) const;
|
|
|
|
bool hasAttribute(StringRef Kind) const;
|
2012-10-08 21:47:17 +00:00
|
|
|
|
2013-02-05 22:37:24 +00:00
|
|
|
Attribute::AttrKind getKindAsEnum() const;
|
|
|
|
uint64_t getValueAsInt() const;
|
2012-12-30 01:38:39 +00:00
|
|
|
|
2013-02-05 22:37:24 +00:00
|
|
|
StringRef getKindAsString() const;
|
|
|
|
StringRef getValueAsString() const;
|
2012-12-30 01:38:39 +00:00
|
|
|
|
2013-01-31 20:59:05 +00:00
|
|
|
/// \brief Used when sorting the attributes.
|
2013-01-24 00:06:56 +00:00
|
|
|
bool operator<(const AttributeImpl &AI) const;
|
|
|
|
|
2012-09-26 21:07:29 +00:00
|
|
|
void Profile(FoldingSetNodeID &ID) const {
|
2013-02-05 22:37:24 +00:00
|
|
|
if (isEnumAttribute())
|
|
|
|
Profile(ID, getKindAsEnum(), 0);
|
2014-07-18 06:51:55 +00:00
|
|
|
else if (isIntAttribute())
|
2013-02-05 22:37:24 +00:00
|
|
|
Profile(ID, getKindAsEnum(), getValueAsInt());
|
|
|
|
else
|
|
|
|
Profile(ID, getKindAsString(), getValueAsString());
|
|
|
|
}
|
2017-05-15 21:57:41 +00:00
|
|
|
|
2013-02-05 22:37:24 +00:00
|
|
|
static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
|
|
|
|
uint64_t Val) {
|
|
|
|
ID.AddInteger(Kind);
|
|
|
|
if (Val) ID.AddInteger(Val);
|
2012-09-26 21:07:29 +00:00
|
|
|
}
|
2017-05-15 21:57:41 +00:00
|
|
|
|
2013-02-05 22:37:24 +00:00
|
|
|
static void Profile(FoldingSetNodeID &ID, StringRef Kind, StringRef Values) {
|
|
|
|
ID.AddString(Kind);
|
2013-02-28 21:17:03 +00:00
|
|
|
if (!Values.empty()) ID.AddString(Values);
|
2013-01-29 00:34:06 +00:00
|
|
|
}
|
2012-09-26 21:07:29 +00:00
|
|
|
};
|
|
|
|
|
2013-07-11 12:13:16 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
|
|
|
/// \brief A set of classes that contain the value of the
|
|
|
|
/// attribute object. There are three main categories: enum attribute entries,
|
|
|
|
/// represented by Attribute::AttrKind; alignment attribute entries; and string
|
|
|
|
/// attribute enties, which are for target-dependent attributes.
|
|
|
|
|
2013-09-11 18:05:11 +00:00
|
|
|
class EnumAttributeImpl : public AttributeImpl {
|
2013-11-19 00:57:56 +00:00
|
|
|
virtual void anchor();
|
2017-06-19 22:05:08 +00:00
|
|
|
|
2013-07-11 12:13:16 +00:00
|
|
|
Attribute::AttrKind Kind;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
EnumAttributeImpl(AttrEntryKind ID, Attribute::AttrKind Kind)
|
|
|
|
: AttributeImpl(ID), Kind(Kind) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
EnumAttributeImpl(Attribute::AttrKind Kind)
|
|
|
|
: AttributeImpl(EnumAttrEntry), Kind(Kind) {}
|
|
|
|
|
|
|
|
Attribute::AttrKind getEnumKind() const { return Kind; }
|
|
|
|
};
|
|
|
|
|
2014-07-18 06:51:55 +00:00
|
|
|
class IntAttributeImpl : public EnumAttributeImpl {
|
|
|
|
uint64_t Val;
|
2013-07-11 12:13:16 +00:00
|
|
|
|
2017-05-15 21:57:41 +00:00
|
|
|
void anchor() override;
|
|
|
|
|
2013-07-11 12:13:16 +00:00
|
|
|
public:
|
2014-07-18 06:51:55 +00:00
|
|
|
IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val)
|
|
|
|
: EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) {
|
2015-04-16 20:29:50 +00:00
|
|
|
assert((Kind == Attribute::Alignment || Kind == Attribute::StackAlignment ||
|
|
|
|
Kind == Attribute::Dereferenceable ||
|
2016-04-12 01:05:35 +00:00
|
|
|
Kind == Attribute::DereferenceableOrNull ||
|
|
|
|
Kind == Attribute::AllocSize) &&
|
2015-04-16 20:29:50 +00:00
|
|
|
"Wrong kind for int attribute!");
|
2013-07-11 12:13:16 +00:00
|
|
|
}
|
|
|
|
|
2014-07-18 06:51:55 +00:00
|
|
|
uint64_t getValue() const { return Val; }
|
2013-07-11 12:13:16 +00:00
|
|
|
};
|
|
|
|
|
2013-09-11 18:05:11 +00:00
|
|
|
class StringAttributeImpl : public AttributeImpl {
|
2013-11-19 00:57:56 +00:00
|
|
|
virtual void anchor();
|
2017-06-19 22:05:08 +00:00
|
|
|
|
2013-07-11 12:13:16 +00:00
|
|
|
std::string Kind;
|
|
|
|
std::string Val;
|
|
|
|
|
|
|
|
public:
|
|
|
|
StringAttributeImpl(StringRef Kind, StringRef Val = StringRef())
|
|
|
|
: AttributeImpl(StringAttrEntry), Kind(Kind), Val(Val) {}
|
|
|
|
|
|
|
|
StringRef getStringKind() const { return Kind; }
|
|
|
|
StringRef getStringValue() const { return Val; }
|
|
|
|
};
|
|
|
|
|
2017-04-12 00:38:00 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
|
|
|
/// \brief This class represents a group of attributes that apply to one
|
|
|
|
/// element: function, return type, or parameter.
|
|
|
|
class AttributeSetNode final
|
|
|
|
: public FoldingSetNode,
|
|
|
|
private TrailingObjects<AttributeSetNode, Attribute> {
|
|
|
|
friend TrailingObjects;
|
|
|
|
|
|
|
|
/// Bitset with a bit for each available attribute Attribute::AttrKind.
|
|
|
|
uint64_t AvailableAttrs;
|
|
|
|
unsigned NumAttrs; ///< Number of attributes in this node.
|
|
|
|
|
|
|
|
AttributeSetNode(ArrayRef<Attribute> Attrs);
|
|
|
|
|
|
|
|
public:
|
|
|
|
// AttributesSetNode is uniqued, these should not be available.
|
|
|
|
AttributeSetNode(const AttributeSetNode &) = delete;
|
|
|
|
AttributeSetNode &operator=(const AttributeSetNode &) = delete;
|
|
|
|
|
|
|
|
void operator delete(void *p) { ::operator delete(p); }
|
|
|
|
|
|
|
|
static AttributeSetNode *get(LLVMContext &C, const AttrBuilder &B);
|
|
|
|
|
|
|
|
static AttributeSetNode *get(LLVMContext &C, ArrayRef<Attribute> Attrs);
|
|
|
|
|
|
|
|
/// \brief Return the number of attributes this AttributeList contains.
|
|
|
|
unsigned getNumAttributes() const { return NumAttrs; }
|
|
|
|
|
|
|
|
bool hasAttribute(Attribute::AttrKind Kind) const {
|
|
|
|
return AvailableAttrs & ((uint64_t)1) << Kind;
|
|
|
|
}
|
|
|
|
bool hasAttribute(StringRef Kind) const;
|
|
|
|
bool hasAttributes() const { return NumAttrs != 0; }
|
|
|
|
|
|
|
|
Attribute getAttribute(Attribute::AttrKind Kind) const;
|
|
|
|
Attribute getAttribute(StringRef Kind) const;
|
|
|
|
|
|
|
|
unsigned getAlignment() const;
|
|
|
|
unsigned getStackAlignment() const;
|
|
|
|
uint64_t getDereferenceableBytes() const;
|
|
|
|
uint64_t getDereferenceableOrNullBytes() const;
|
|
|
|
std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
|
|
|
|
std::string getAsString(bool InAttrGrp) const;
|
|
|
|
|
2017-05-15 21:57:41 +00:00
|
|
|
using iterator = const Attribute *;
|
|
|
|
|
2017-04-12 00:38:00 +00:00
|
|
|
iterator begin() const { return getTrailingObjects<Attribute>(); }
|
|
|
|
iterator end() const { return begin() + NumAttrs; }
|
|
|
|
|
|
|
|
void Profile(FoldingSetNodeID &ID) const {
|
|
|
|
Profile(ID, makeArrayRef(begin(), end()));
|
|
|
|
}
|
2017-05-15 21:57:41 +00:00
|
|
|
|
2017-04-12 00:38:00 +00:00
|
|
|
static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
|
|
|
|
for (const auto &Attr : AttrList)
|
|
|
|
Attr.Profile(ID);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-05-15 21:57:41 +00:00
|
|
|
using IndexAttrPair = std::pair<unsigned, AttributeSet>;
|
2015-08-06 09:49:17 +00:00
|
|
|
|
2013-01-24 00:06:56 +00:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
|
|
|
/// \brief This class represents a set of attributes that apply to the function,
|
|
|
|
/// return type, and parameters.
|
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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298393 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-21 16:57:19 +00:00
|
|
|
class AttributeListImpl final
|
2015-08-05 22:57:34 +00:00
|
|
|
: public FoldingSetNode,
|
[IR] Switch AttributeList to use an array for O(1) access
Summary:
Before this change, AttributeLists stored a pair of index and
AttributeSet. This is memory efficient if most arguments do not have
attributes. However, it requires doing a search over the pairs to test
an argument or function attribute. Profiling shows that this loop was
0.76% of the time in 'opt -O2' of sqlite3.c, because LLVM constantly
tests values for nullability.
This was worth about 2.5% of mid-level optimization cycles on the
sqlite3 amalgamation. Here are the full perf results:
https://reviews.llvm.org/P7995
Here are just the before and after cycle counts:
```
$ perf stat -r 5 ./opt_before -O2 sqlite3.bc -o /dev/null
13,274,181,184 cycles # 3.047 GHz ( +- 0.28% )
$ perf stat -r 5 ./opt_after -O2 sqlite3.bc -o /dev/null
12,906,927,263 cycles # 3.043 GHz ( +- 0.51% )
```
This patch *does not* change the indices used to query attributes, as
requested by reviewers. Tracking whether an index is usable for array
indexing is a huge pain that affects many of the internal APIs, so it
would be good to come back later and do a cleanup to remove this
internal adjustment.
Reviewers: pete, chandlerc
Subscribers: javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D32819
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303654 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23 17:01:48 +00:00
|
|
|
private TrailingObjects<AttributeListImpl, AttributeSet> {
|
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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298393 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-21 16:57:19 +00:00
|
|
|
friend class AttributeList;
|
2015-08-05 22:57:34 +00:00
|
|
|
friend TrailingObjects;
|
2015-06-17 01:21:20 +00:00
|
|
|
|
|
|
|
private:
|
2016-01-29 22:25:19 +00:00
|
|
|
/// Bitset with a bit for each available attribute Attribute::AttrKind.
|
|
|
|
uint64_t AvailableFunctionAttrs;
|
[IR] Switch AttributeList to use an array for O(1) access
Summary:
Before this change, AttributeLists stored a pair of index and
AttributeSet. This is memory efficient if most arguments do not have
attributes. However, it requires doing a search over the pairs to test
an argument or function attribute. Profiling shows that this loop was
0.76% of the time in 'opt -O2' of sqlite3.c, because LLVM constantly
tests values for nullability.
This was worth about 2.5% of mid-level optimization cycles on the
sqlite3 amalgamation. Here are the full perf results:
https://reviews.llvm.org/P7995
Here are just the before and after cycle counts:
```
$ perf stat -r 5 ./opt_before -O2 sqlite3.bc -o /dev/null
13,274,181,184 cycles # 3.047 GHz ( +- 0.28% )
$ perf stat -r 5 ./opt_after -O2 sqlite3.bc -o /dev/null
12,906,927,263 cycles # 3.043 GHz ( +- 0.51% )
```
This patch *does not* change the indices used to query attributes, as
requested by reviewers. Tracking whether an index is usable for array
indexing is a huge pain that affects many of the internal APIs, so it
would be good to come back later and do a cleanup to remove this
internal adjustment.
Reviewers: pete, chandlerc
Subscribers: javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D32819
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303654 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23 17:01:48 +00:00
|
|
|
LLVMContext &Context;
|
|
|
|
unsigned NumAttrSets; ///< Number of entries in this set.
|
2013-07-11 12:13:16 +00:00
|
|
|
|
2015-08-05 22:57:34 +00:00
|
|
|
// Helper fn for TrailingObjects class.
|
[IR] Switch AttributeList to use an array for O(1) access
Summary:
Before this change, AttributeLists stored a pair of index and
AttributeSet. This is memory efficient if most arguments do not have
attributes. However, it requires doing a search over the pairs to test
an argument or function attribute. Profiling shows that this loop was
0.76% of the time in 'opt -O2' of sqlite3.c, because LLVM constantly
tests values for nullability.
This was worth about 2.5% of mid-level optimization cycles on the
sqlite3 amalgamation. Here are the full perf results:
https://reviews.llvm.org/P7995
Here are just the before and after cycle counts:
```
$ perf stat -r 5 ./opt_before -O2 sqlite3.bc -o /dev/null
13,274,181,184 cycles # 3.047 GHz ( +- 0.28% )
$ perf stat -r 5 ./opt_after -O2 sqlite3.bc -o /dev/null
12,906,927,263 cycles # 3.043 GHz ( +- 0.51% )
```
This patch *does not* change the indices used to query attributes, as
requested by reviewers. Tracking whether an index is usable for array
indexing is a huge pain that affects many of the internal APIs, so it
would be good to come back later and do a cleanup to remove this
internal adjustment.
Reviewers: pete, chandlerc
Subscribers: javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D32819
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303654 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23 17:01:48 +00:00
|
|
|
size_t numTrailingObjects(OverloadToken<AttributeSet>) { return NumAttrSets; }
|
2013-01-24 01:01:34 +00:00
|
|
|
|
2012-11-20 05:09:20 +00:00
|
|
|
public:
|
[IR] Switch AttributeList to use an array for O(1) access
Summary:
Before this change, AttributeLists stored a pair of index and
AttributeSet. This is memory efficient if most arguments do not have
attributes. However, it requires doing a search over the pairs to test
an argument or function attribute. Profiling shows that this loop was
0.76% of the time in 'opt -O2' of sqlite3.c, because LLVM constantly
tests values for nullability.
This was worth about 2.5% of mid-level optimization cycles on the
sqlite3 amalgamation. Here are the full perf results:
https://reviews.llvm.org/P7995
Here are just the before and after cycle counts:
```
$ perf stat -r 5 ./opt_before -O2 sqlite3.bc -o /dev/null
13,274,181,184 cycles # 3.047 GHz ( +- 0.28% )
$ perf stat -r 5 ./opt_after -O2 sqlite3.bc -o /dev/null
12,906,927,263 cycles # 3.043 GHz ( +- 0.51% )
```
This patch *does not* change the indices used to query attributes, as
requested by reviewers. Tracking whether an index is usable for array
indexing is a huge pain that affects many of the internal APIs, so it
would be good to come back later and do a cleanup to remove this
internal adjustment.
Reviewers: pete, chandlerc
Subscribers: javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D32819
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303654 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23 17:01:48 +00:00
|
|
|
AttributeListImpl(LLVMContext &C, ArrayRef<AttributeSet> Sets);
|
2013-01-04 20:54:35 +00:00
|
|
|
|
2016-12-07 22:06:02 +00:00
|
|
|
// AttributesSetImpt is uniqued, these should not be available.
|
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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298393 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-21 16:57:19 +00:00
|
|
|
AttributeListImpl(const AttributeListImpl &) = delete;
|
|
|
|
AttributeListImpl &operator=(const AttributeListImpl &) = delete;
|
2016-12-07 22:06:02 +00:00
|
|
|
|
2016-02-09 02:09:16 +00:00
|
|
|
void operator delete(void *p) { ::operator delete(p); }
|
2016-02-09 01:03:42 +00: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
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@298393 91177308-0d34-0410-b5e6-96231b3b80d8
2017-03-21 16:57:19 +00:00
|
|
|
/// \brief Get the context that created this AttributeListImpl.
|
2013-01-04 20:54:35 +00:00
|
|
|
LLVMContext &getContext() { return Context; }
|
2013-01-27 21:32:11 +00:00
|
|
|
|
2017-04-12 00:38:00 +00:00
|
|
|
/// \brief Return true if the AttributeSet or the FunctionIndex has an
|
2016-01-29 22:25:19 +00:00
|
|
|
/// enum attribute of the given kind.
|
|
|
|
bool hasFnAttribute(Attribute::AttrKind Kind) const {
|
|
|
|
return AvailableFunctionAttrs & ((uint64_t)1) << Kind;
|
|
|
|
}
|
|
|
|
|
2017-06-19 22:05:08 +00:00
|
|
|
using iterator = const AttributeSet *;
|
|
|
|
|
[IR] Switch AttributeList to use an array for O(1) access
Summary:
Before this change, AttributeLists stored a pair of index and
AttributeSet. This is memory efficient if most arguments do not have
attributes. However, it requires doing a search over the pairs to test
an argument or function attribute. Profiling shows that this loop was
0.76% of the time in 'opt -O2' of sqlite3.c, because LLVM constantly
tests values for nullability.
This was worth about 2.5% of mid-level optimization cycles on the
sqlite3 amalgamation. Here are the full perf results:
https://reviews.llvm.org/P7995
Here are just the before and after cycle counts:
```
$ perf stat -r 5 ./opt_before -O2 sqlite3.bc -o /dev/null
13,274,181,184 cycles # 3.047 GHz ( +- 0.28% )
$ perf stat -r 5 ./opt_after -O2 sqlite3.bc -o /dev/null
12,906,927,263 cycles # 3.043 GHz ( +- 0.51% )
```
This patch *does not* change the indices used to query attributes, as
requested by reviewers. Tracking whether an index is usable for array
indexing is a huge pain that affects many of the internal APIs, so it
would be good to come back later and do a cleanup to remove this
internal adjustment.
Reviewers: pete, chandlerc
Subscribers: javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D32819
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303654 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23 17:01:48 +00:00
|
|
|
iterator begin() const { return getTrailingObjects<AttributeSet>(); }
|
|
|
|
iterator end() const { return begin() + NumAttrSets; }
|
2013-01-28 00:21:34 +00:00
|
|
|
|
2017-04-11 00:16:00 +00:00
|
|
|
void Profile(FoldingSetNodeID &ID) const;
|
[IR] Switch AttributeList to use an array for O(1) access
Summary:
Before this change, AttributeLists stored a pair of index and
AttributeSet. This is memory efficient if most arguments do not have
attributes. However, it requires doing a search over the pairs to test
an argument or function attribute. Profiling shows that this loop was
0.76% of the time in 'opt -O2' of sqlite3.c, because LLVM constantly
tests values for nullability.
This was worth about 2.5% of mid-level optimization cycles on the
sqlite3 amalgamation. Here are the full perf results:
https://reviews.llvm.org/P7995
Here are just the before and after cycle counts:
```
$ perf stat -r 5 ./opt_before -O2 sqlite3.bc -o /dev/null
13,274,181,184 cycles # 3.047 GHz ( +- 0.28% )
$ perf stat -r 5 ./opt_after -O2 sqlite3.bc -o /dev/null
12,906,927,263 cycles # 3.043 GHz ( +- 0.51% )
```
This patch *does not* change the indices used to query attributes, as
requested by reviewers. Tracking whether an index is usable for array
indexing is a huge pain that affects many of the internal APIs, so it
would be good to come back later and do a cleanup to remove this
internal adjustment.
Reviewers: pete, chandlerc
Subscribers: javed.absar, llvm-commits
Differential Revision: https://reviews.llvm.org/D32819
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@303654 91177308-0d34-0410-b5e6-96231b3b80d8
2017-05-23 17:01:48 +00:00
|
|
|
static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeSet> Nodes);
|
2013-01-27 23:41:29 +00:00
|
|
|
|
2013-08-02 22:34:30 +00:00
|
|
|
void dump() const;
|
2012-11-20 05:09:20 +00:00
|
|
|
};
|
|
|
|
|
2016-12-07 22:06:02 +00:00
|
|
|
} // end namespace llvm
|
2012-09-26 21:07:29 +00:00
|
|
|
|
2016-12-07 22:06:02 +00:00
|
|
|
#endif // LLVM_LIB_IR_ATTRIBUTEIMPL_H
|