2017-02-17 01:00:09 +01:00
|
|
|
//===- llvm/Attributes.h - Container for Attributes -------------*- C++ -*-===//
|
2007-04-08 16:46:50 +02:00
|
|
|
//
|
|
|
|
// The LLVM Compiler Infrastructure
|
|
|
|
//
|
2007-12-29 20:59:42 +01:00
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
2007-04-08 16:46:50 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2018-03-30 02:47:31 +02:00
|
|
|
//
|
2012-12-20 22:28:43 +01:00
|
|
|
/// \file
|
|
|
|
/// \brief This file contains the simple types necessary to represent the
|
|
|
|
/// attributes associated with functions and their calls.
|
2018-03-30 02:47:31 +02:00
|
|
|
//
|
2007-04-08 16:46:50 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2013-01-10 01:45:19 +01:00
|
|
|
#ifndef LLVM_IR_ATTRIBUTES_H
|
|
|
|
#define LLVM_IR_ATTRIBUTES_H
|
2007-04-08 16:46:50 +02:00
|
|
|
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm-c/Types.h"
|
2012-05-28 03:47:44 +02:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2013-01-24 01:06:56 +01:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2016-04-12 03:05:35 +02:00
|
|
|
#include "llvm/ADT/Optional.h"
|
2017-02-17 01:00:09 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2017-06-06 13:49:48 +02:00
|
|
|
#include "llvm/ADT/iterator_range.h"
|
2013-02-16 20:13:18 +01:00
|
|
|
#include "llvm/Support/PointerLikeTypeTraits.h"
|
2013-02-18 13:09:51 +01:00
|
|
|
#include <bitset>
|
2013-01-03 02:54:39 +01:00
|
|
|
#include <cassert>
|
2017-02-17 01:00:09 +01:00
|
|
|
#include <cstdint>
|
2013-02-05 09:09:32 +01:00
|
|
|
#include <map>
|
2008-03-12 18:45:29 +01:00
|
|
|
#include <string>
|
2017-02-17 01:00:09 +01:00
|
|
|
#include <utility>
|
2007-04-08 16:46:50 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
2012-09-15 01:05:52 +02:00
|
|
|
|
2012-10-15 22:35:56 +02:00
|
|
|
class AttrBuilder;
|
2012-12-20 02:36:59 +01:00
|
|
|
class AttributeImpl;
|
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
|
|
|
class AttributeListImpl;
|
2013-01-29 01:48:16 +01:00
|
|
|
class AttributeSetNode;
|
2013-02-16 20:13:18 +01:00
|
|
|
template<typename T> struct DenseMapInfo;
|
2015-12-23 00:57:37 +01:00
|
|
|
class Function;
|
2012-09-26 23:07:29 +02:00
|
|
|
class LLVMContext;
|
2008-01-06 19:27:01 +01:00
|
|
|
class Type;
|
|
|
|
|
2012-12-19 09:57:40 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2012-12-20 22:28:43 +01:00
|
|
|
/// \class
|
|
|
|
/// \brief Functions, function parameters, and return types can have attributes
|
2012-12-19 09:57:40 +01:00
|
|
|
/// to indicate how they should be treated by optimizations and code
|
|
|
|
/// generation. This class represents one of those attributes. It's light-weight
|
|
|
|
/// and should be passed around by-value.
|
2012-12-19 08:18:57 +01:00
|
|
|
class Attribute {
|
2012-10-09 09:45:08 +02:00
|
|
|
public:
|
2012-12-19 09:57:40 +01:00
|
|
|
/// This enumeration lists the attributes that can be associated with
|
2013-01-31 01:29:54 +01:00
|
|
|
/// parameters, function results, or the function itself.
|
2012-10-16 08:10:45 +02:00
|
|
|
///
|
2013-01-31 01:29:54 +01:00
|
|
|
/// Note: The `uwtable' attribute is about the ABI or the user mandating an
|
|
|
|
/// entry in the unwind table. The `nounwind' attribute is about an exception
|
|
|
|
/// passing by the function.
|
2012-10-16 08:10:45 +02:00
|
|
|
///
|
2013-01-31 01:29:54 +01:00
|
|
|
/// In a theoretical system that uses tables for profiling and SjLj for
|
2012-10-10 08:13:42 +02:00
|
|
|
/// exceptions, they would be fully independent. In a normal system that uses
|
|
|
|
/// tables for both, the semantics are:
|
2012-10-16 08:10:45 +02:00
|
|
|
///
|
2012-10-10 08:13:42 +02:00
|
|
|
/// nil = Needs an entry because an exception might pass by.
|
|
|
|
/// nounwind = No need for an entry
|
|
|
|
/// uwtable = Needs an entry because the ABI says so and because
|
|
|
|
/// an exception might pass by.
|
|
|
|
/// uwtable + nounwind = Needs an entry because the ABI says so.
|
|
|
|
|
2012-12-22 01:37:52 +01:00
|
|
|
enum AttrKind {
|
2012-10-15 21:58:25 +02:00
|
|
|
// IR-Level Attributes
|
2012-10-26 21:52:54 +02:00
|
|
|
None, ///< No attributes have been set
|
2015-11-11 21:35:42 +01:00
|
|
|
#define GET_ATTR_ENUM
|
2016-09-29 05:35:19 +02:00
|
|
|
#include "llvm/IR/Attributes.gen"
|
2013-02-16 20:15:28 +01:00
|
|
|
EndAttrKinds ///< Sentinal value useful for loops
|
2012-10-09 09:45:08 +02:00
|
|
|
};
|
2015-09-22 13:14:39 +02:00
|
|
|
|
2012-10-09 09:45:08 +02:00
|
|
|
private:
|
2017-02-17 01:00:09 +01:00
|
|
|
AttributeImpl *pImpl = nullptr;
|
|
|
|
|
2012-12-20 22:28:43 +01:00
|
|
|
Attribute(AttributeImpl *A) : pImpl(A) {}
|
2015-09-22 13:14:39 +02:00
|
|
|
|
2012-09-15 01:05:52 +02:00
|
|
|
public:
|
2017-02-17 01:00:09 +01:00
|
|
|
Attribute() = default;
|
2012-09-26 23:07:29 +02:00
|
|
|
|
2013-01-29 01:34:06 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Attribute Construction
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2013-01-27 23:43:04 +01:00
|
|
|
/// \brief Return a uniquified Attribute object.
|
2014-09-04 01:38:05 +02:00
|
|
|
static Attribute get(LLVMContext &Context, AttrKind Kind, uint64_t Val = 0);
|
2013-02-05 23:37:24 +01:00
|
|
|
static Attribute get(LLVMContext &Context, StringRef Kind,
|
|
|
|
StringRef Val = StringRef());
|
2012-09-26 23:07:29 +02:00
|
|
|
|
2013-01-27 23:43:04 +01:00
|
|
|
/// \brief Return a uniquified Attribute object that has the specific
|
|
|
|
/// alignment set.
|
|
|
|
static Attribute getWithAlignment(LLVMContext &Context, uint64_t Align);
|
|
|
|
static Attribute getWithStackAlignment(LLVMContext &Context, uint64_t Align);
|
2014-07-18 17:51:28 +02:00
|
|
|
static Attribute getWithDereferenceableBytes(LLVMContext &Context,
|
|
|
|
uint64_t Bytes);
|
2015-04-16 22:29:50 +02:00
|
|
|
static Attribute getWithDereferenceableOrNullBytes(LLVMContext &Context,
|
|
|
|
uint64_t Bytes);
|
2016-04-12 03:05:35 +02:00
|
|
|
static Attribute getWithAllocSizeArgs(LLVMContext &Context,
|
|
|
|
unsigned ElemSizeArg,
|
|
|
|
const Optional<unsigned> &NumElemsArg);
|
2013-01-27 23:43:04 +01:00
|
|
|
|
2013-01-29 01:34:06 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// Attribute Accessors
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
/// \brief Return true if the attribute is an Attribute::AttrKind type.
|
|
|
|
bool isEnumAttribute() const;
|
|
|
|
|
2014-07-18 08:51:55 +02:00
|
|
|
/// \brief Return true if the attribute is an integer attribute.
|
|
|
|
bool isIntAttribute() const;
|
2013-02-05 23:37:24 +01:00
|
|
|
|
|
|
|
/// \brief Return true if the attribute is a string (target-dependent)
|
|
|
|
/// attribute.
|
|
|
|
bool isStringAttribute() const;
|
|
|
|
|
2013-01-31 04:47:28 +01:00
|
|
|
/// \brief Return true if the attribute is present.
|
|
|
|
bool hasAttribute(AttrKind Val) const;
|
|
|
|
|
2013-02-06 00:48:36 +01:00
|
|
|
/// \brief Return true if the target-dependent attribute is present.
|
|
|
|
bool hasAttribute(StringRef Val) const;
|
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
/// \brief Return the attribute's kind as an enum (Attribute::AttrKind). This
|
2016-01-23 23:38:39 +01:00
|
|
|
/// requires the attribute to be an enum or integer attribute.
|
2013-02-05 23:37:24 +01:00
|
|
|
Attribute::AttrKind getKindAsEnum() const;
|
2013-01-29 21:45:34 +01:00
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
/// \brief Return the attribute's value as an integer. This requires that the
|
2016-01-23 23:38:39 +01:00
|
|
|
/// attribute be an integer attribute.
|
2013-02-05 23:37:24 +01:00
|
|
|
uint64_t getValueAsInt() const;
|
|
|
|
|
|
|
|
/// \brief Return the attribute's kind as a string. This requires the
|
|
|
|
/// attribute to be a string attribute.
|
|
|
|
StringRef getKindAsString() const;
|
|
|
|
|
|
|
|
/// \brief Return the attribute's value as a string. This requires the
|
|
|
|
/// attribute to be a string attribute.
|
|
|
|
StringRef getValueAsString() const;
|
2013-01-29 21:45:34 +01:00
|
|
|
|
2012-12-19 09:57:40 +01:00
|
|
|
/// \brief Returns the alignment field of an attribute as a byte alignment
|
2012-09-21 17:26:31 +02:00
|
|
|
/// value.
|
2012-10-05 08:44:41 +02:00
|
|
|
unsigned getAlignment() const;
|
2012-09-21 17:26:31 +02:00
|
|
|
|
2012-12-19 09:57:40 +01:00
|
|
|
/// \brief Returns the stack alignment field of an attribute as a byte
|
2012-10-09 11:51:10 +02:00
|
|
|
/// alignment value.
|
2012-10-05 08:44:41 +02:00
|
|
|
unsigned getStackAlignment() const;
|
2012-09-21 18:07:28 +02:00
|
|
|
|
2014-07-18 17:51:28 +02:00
|
|
|
/// \brief Returns the number of dereferenceable bytes from the
|
2015-12-16 06:21:02 +01:00
|
|
|
/// dereferenceable attribute.
|
2014-07-18 17:51:28 +02:00
|
|
|
uint64_t getDereferenceableBytes() const;
|
|
|
|
|
2015-04-16 22:29:50 +02:00
|
|
|
/// \brief Returns the number of dereferenceable_or_null bytes from the
|
2015-12-16 06:21:02 +01:00
|
|
|
/// dereferenceable_or_null attribute.
|
2015-04-16 22:29:50 +02:00
|
|
|
uint64_t getDereferenceableOrNullBytes() const;
|
|
|
|
|
2016-04-12 03:05:35 +02:00
|
|
|
/// Returns the argument numbers for the allocsize attribute (or pair(0, 0)
|
|
|
|
/// if not known).
|
|
|
|
std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
|
|
|
|
|
2013-01-29 01:34:06 +01:00
|
|
|
/// \brief The Attribute is converted to a string of equivalent mnemonic. This
|
|
|
|
/// is, presumably, for writing out the mnemonics for the assembly writer.
|
2013-02-11 09:43:33 +01:00
|
|
|
std::string getAsString(bool InAttrGrp = false) const;
|
2013-01-29 01:34:06 +01:00
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
/// \brief Equality and non-equality operators.
|
2013-01-27 23:46:17 +01:00
|
|
|
bool operator==(Attribute A) const { return pImpl == A.pImpl; }
|
|
|
|
bool operator!=(Attribute A) const { return pImpl != A.pImpl; }
|
|
|
|
|
2013-01-27 23:43:04 +01:00
|
|
|
/// \brief Less-than operator. Useful for sorting the attributes list.
|
2013-01-24 01:06:56 +01:00
|
|
|
bool operator<(Attribute A) const;
|
|
|
|
|
2013-01-24 02:01:34 +01:00
|
|
|
void Profile(FoldingSetNodeID &ID) const {
|
|
|
|
ID.AddPointer(pImpl);
|
|
|
|
}
|
2016-06-12 08:17:24 +02:00
|
|
|
|
|
|
|
/// \brief Return a raw pointer that uniquely identifies this attribute.
|
|
|
|
void *getRawPointer() const {
|
|
|
|
return pImpl;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Get an attribute from a raw pointer created by getRawPointer.
|
|
|
|
static Attribute fromRawPointer(void *RawPtr) {
|
|
|
|
return Attribute(reinterpret_cast<AttributeImpl*>(RawPtr));
|
|
|
|
}
|
2007-11-25 15:10:56 +01:00
|
|
|
};
|
|
|
|
|
2016-06-12 08:17:24 +02:00
|
|
|
// Specialized opaque value conversions.
|
|
|
|
inline LLVMAttributeRef wrap(Attribute Attr) {
|
|
|
|
return reinterpret_cast<LLVMAttributeRef>(Attr.getRawPointer());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Specialized opaque value conversions.
|
|
|
|
inline Attribute unwrap(LLVMAttributeRef Attr) {
|
|
|
|
return Attribute::fromRawPointer(Attr);
|
|
|
|
}
|
|
|
|
|
2017-04-12 02:38:00 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
|
|
|
/// This class holds the attributes for a particular argument, parameter,
|
|
|
|
/// function, or return value. It is an immutable value type that is cheap to
|
|
|
|
/// copy. Adding and removing enum attributes is intended to be fast, but adding
|
|
|
|
/// and removing string or integer attributes involves a FoldingSet lookup.
|
|
|
|
class AttributeSet {
|
2018-03-30 02:47:31 +02:00
|
|
|
friend AttributeListImpl;
|
|
|
|
template <typename Ty> friend struct DenseMapInfo;
|
|
|
|
|
2017-04-12 02:38:00 +02:00
|
|
|
// TODO: Extract AvailableAttrs from AttributeSetNode and store them here.
|
|
|
|
// This will allow an efficient implementation of addAttribute and
|
|
|
|
// removeAttribute for enum attrs.
|
|
|
|
|
|
|
|
/// Private implementation pointer.
|
|
|
|
AttributeSetNode *SetNode = nullptr;
|
|
|
|
|
|
|
|
private:
|
2017-04-13 00:30:37 +02:00
|
|
|
explicit AttributeSet(AttributeSetNode *ASN) : SetNode(ASN) {}
|
2017-04-12 02:38:00 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
/// AttributeSet is a trivially copyable value type.
|
|
|
|
AttributeSet() = default;
|
|
|
|
AttributeSet(const AttributeSet &) = default;
|
|
|
|
~AttributeSet() = default;
|
|
|
|
|
|
|
|
static AttributeSet get(LLVMContext &C, const AttrBuilder &B);
|
|
|
|
static AttributeSet get(LLVMContext &C, ArrayRef<Attribute> Attrs);
|
|
|
|
|
2017-11-14 19:08:05 +01:00
|
|
|
bool operator==(const AttributeSet &O) const { return SetNode == O.SetNode; }
|
|
|
|
bool operator!=(const AttributeSet &O) const { return !(*this == O); }
|
2017-04-12 02:38:00 +02:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Add an argument attribute. Returns a new set because attribute sets are
|
|
|
|
/// immutable.
|
|
|
|
AttributeSet addAttribute(LLVMContext &C, Attribute::AttrKind Kind) const;
|
2017-05-11 14:28:08 +02:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Add a target-dependent attribute. Returns a new set because attribute sets
|
|
|
|
/// are immutable.
|
2017-05-11 14:28:08 +02:00
|
|
|
AttributeSet addAttribute(LLVMContext &C, StringRef Kind,
|
|
|
|
StringRef Value = StringRef()) const;
|
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Add attributes to the attribute set. Returns a new set because attribute
|
|
|
|
/// sets are immutable.
|
2017-05-11 14:28:08 +02:00
|
|
|
AttributeSet addAttributes(LLVMContext &C, AttributeSet AS) const;
|
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Remove the specified attribute from this set. Returns a new set because
|
|
|
|
/// attribute sets are immutable.
|
|
|
|
AttributeSet removeAttribute(LLVMContext &C, Attribute::AttrKind Kind) const;
|
2017-05-11 14:28:08 +02:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Remove the specified attribute from this set. Returns a new set because
|
|
|
|
/// attribute sets are immutable.
|
|
|
|
AttributeSet removeAttribute(LLVMContext &C, StringRef Kind) const;
|
2017-05-11 14:28:08 +02:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Remove the specified attributes from this set. Returns a new set because
|
|
|
|
/// attribute sets are immutable.
|
2017-05-11 14:28:08 +02:00
|
|
|
AttributeSet removeAttributes(LLVMContext &C,
|
2017-05-31 21:23:09 +02:00
|
|
|
const AttrBuilder &AttrsToRemove) const;
|
2017-05-11 14:28:08 +02:00
|
|
|
|
|
|
|
/// Return the number of attributes in this set.
|
2017-04-12 02:38:00 +02:00
|
|
|
unsigned getNumAttributes() const;
|
|
|
|
|
2017-05-11 14:28:08 +02:00
|
|
|
/// Return true if attributes exists in this set.
|
2017-04-12 02:38:00 +02:00
|
|
|
bool hasAttributes() const { return SetNode != nullptr; }
|
|
|
|
|
2017-05-11 14:28:08 +02:00
|
|
|
/// Return true if the attribute exists in this set.
|
2017-04-12 02:38:00 +02:00
|
|
|
bool hasAttribute(Attribute::AttrKind Kind) const;
|
2017-05-11 14:28:08 +02:00
|
|
|
|
|
|
|
/// Return true if the attribute exists in this set.
|
2017-04-12 02:38:00 +02:00
|
|
|
bool hasAttribute(StringRef Kind) const;
|
|
|
|
|
2017-05-11 14:28:08 +02:00
|
|
|
/// Return the attribute object.
|
2017-04-12 02:38:00 +02:00
|
|
|
Attribute getAttribute(Attribute::AttrKind Kind) const;
|
2017-05-11 14:28:08 +02:00
|
|
|
|
|
|
|
/// Return the target-dependent attribute object.
|
2017-04-12 02:38:00 +02:00
|
|
|
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;
|
2017-04-14 02:06:06 +02:00
|
|
|
std::string getAsString(bool InAttrGrp = false) const;
|
2017-04-12 02:38:00 +02:00
|
|
|
|
2017-05-06 00:30:37 +02:00
|
|
|
using iterator = const Attribute *;
|
|
|
|
|
2017-04-12 02:38:00 +02:00
|
|
|
iterator begin() const;
|
|
|
|
iterator end() const;
|
2017-10-15 16:32:27 +02:00
|
|
|
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
|
2017-05-11 14:28:08 +02:00
|
|
|
void dump() const;
|
|
|
|
#endif
|
2017-04-12 02:38:00 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
|
|
|
/// \brief Provide DenseMapInfo for AttributeSet.
|
|
|
|
template <> struct DenseMapInfo<AttributeSet> {
|
2018-03-30 02:47:31 +02:00
|
|
|
static AttributeSet getEmptyKey() {
|
|
|
|
auto Val = static_cast<uintptr_t>(-1);
|
2017-04-12 02:38:00 +02:00
|
|
|
Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
|
|
|
|
return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val));
|
|
|
|
}
|
|
|
|
|
2018-03-30 02:47:31 +02:00
|
|
|
static AttributeSet getTombstoneKey() {
|
|
|
|
auto Val = static_cast<uintptr_t>(-2);
|
2017-04-12 02:38:00 +02:00
|
|
|
Val <<= PointerLikeTypeTraits<void *>::NumLowBitsAvailable;
|
|
|
|
return AttributeSet(reinterpret_cast<AttributeSetNode *>(Val));
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned getHashValue(AttributeSet AS) {
|
|
|
|
return (unsigned((uintptr_t)AS.SetNode) >> 4) ^
|
|
|
|
(unsigned((uintptr_t)AS.SetNode) >> 9);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool isEqual(AttributeSet LHS, AttributeSet RHS) { return LHS == RHS; }
|
|
|
|
};
|
|
|
|
|
2012-12-19 23:42:22 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
2012-12-20 22:28:43 +01:00
|
|
|
/// \class
|
2013-02-06 21:05:44 +01:00
|
|
|
/// \brief This class holds the attributes for a function, its return value, and
|
|
|
|
/// its parameters. You access the attributes for each of them via an index into
|
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 object. The function attributes are at index
|
|
|
|
/// `AttributeList::FunctionIndex', the return value is at index
|
|
|
|
/// `AttributeList::ReturnIndex', and the attributes for the parameters start at
|
[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
llvm-svn: 303654
2017-05-23 19:01:48 +02:00
|
|
|
/// index `AttributeList::FirstArgIndex'.
|
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
|
|
|
class AttributeList {
|
2012-10-15 09:29:08 +02:00
|
|
|
public:
|
2014-03-02 04:20:38 +01:00
|
|
|
enum AttrIndex : unsigned {
|
2012-10-15 09:29:08 +02:00
|
|
|
ReturnIndex = 0U,
|
2017-05-03 20:17:31 +02:00
|
|
|
FunctionIndex = ~0U,
|
|
|
|
FirstArgIndex = 1,
|
2012-10-15 09:29:08 +02:00
|
|
|
};
|
2015-09-22 13:14:39 +02:00
|
|
|
|
2012-10-15 09:29:08 +02:00
|
|
|
private:
|
2013-01-07 09:24:35 +01:00
|
|
|
friend class AttrBuilder;
|
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
|
|
|
friend class AttributeListImpl;
|
2017-04-12 02:38:00 +02:00
|
|
|
friend class AttributeSet;
|
2016-07-21 06:25:06 +02:00
|
|
|
friend class AttributeSetNode;
|
2013-02-09 16:42:51 +01:00
|
|
|
template <typename Ty> friend struct DenseMapInfo;
|
2013-01-07 09:24:35 +01:00
|
|
|
|
2013-01-31 01:29:54 +01:00
|
|
|
/// \brief The attributes that we are managing. This can be null to represent
|
2012-11-20 06:09:20 +01:00
|
|
|
/// the empty attributes list.
|
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
|
|
|
AttributeListImpl *pImpl = nullptr;
|
2012-11-20 06:09:20 +01:00
|
|
|
|
2017-04-11 01:31:05 +02:00
|
|
|
public:
|
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
|
|
|
/// \brief Create an AttributeList with the specified parameters in it.
|
|
|
|
static AttributeList get(LLVMContext &C,
|
|
|
|
ArrayRef<std::pair<unsigned, Attribute>> Attrs);
|
[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
llvm-svn: 303654
2017-05-23 19:01:48 +02:00
|
|
|
static AttributeList get(LLVMContext &C,
|
|
|
|
ArrayRef<std::pair<unsigned, AttributeSet>> Attrs);
|
2013-01-28 22:55:20 +01:00
|
|
|
|
2017-04-13 02:58:09 +02:00
|
|
|
/// \brief Create an AttributeList from attribute sets for a function, its
|
|
|
|
/// return value, and all of its arguments.
|
|
|
|
static AttributeList get(LLVMContext &C, AttributeSet FnAttrs,
|
|
|
|
AttributeSet RetAttrs,
|
|
|
|
ArrayRef<AttributeSet> ArgAttrs);
|
2017-04-11 01:31:05 +02:00
|
|
|
|
|
|
|
private:
|
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
|
|
|
explicit AttributeList(AttributeListImpl *LI) : pImpl(LI) {}
|
2015-09-22 13:14:39 +02:00
|
|
|
|
[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
llvm-svn: 303654
2017-05-23 19:01:48 +02:00
|
|
|
static AttributeList getImpl(LLVMContext &C, ArrayRef<AttributeSet> AttrSets);
|
|
|
|
|
2008-03-12 18:45:29 +01:00
|
|
|
public:
|
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() = default;
|
2010-01-04 08:16:12 +01:00
|
|
|
|
2008-03-12 18:45:29 +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
|
|
|
// AttributeList Construction and Mutation
|
2008-03-12 18:45:29 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
2010-01-04 08:16:12 +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
|
|
|
/// \brief Return an AttributeList with the specified parameters in it.
|
|
|
|
static AttributeList get(LLVMContext &C, ArrayRef<AttributeList> Attrs);
|
|
|
|
static AttributeList get(LLVMContext &C, unsigned Index,
|
|
|
|
ArrayRef<Attribute::AttrKind> Kinds);
|
|
|
|
static AttributeList get(LLVMContext &C, unsigned Index,
|
|
|
|
ArrayRef<StringRef> Kind);
|
|
|
|
static AttributeList get(LLVMContext &C, unsigned Index,
|
|
|
|
const AttrBuilder &B);
|
2008-03-12 18:45:29 +01:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \brief Add an attribute to the attribute set at the given index.
|
|
|
|
/// Returns a new list because attribute lists are immutable.
|
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 addAttribute(LLVMContext &C, unsigned Index,
|
|
|
|
Attribute::AttrKind Kind) const;
|
2010-01-04 08:16:12 +01:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \brief Add an attribute to the attribute set at the given index.
|
|
|
|
/// Returns a new list because attribute lists are immutable.
|
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 addAttribute(LLVMContext &C, unsigned Index, StringRef Kind,
|
|
|
|
StringRef Value = StringRef()) const;
|
2013-03-13 21:20:08 +01:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Add an attribute to the attribute set at the given index.
|
|
|
|
/// Returns a new list because attribute lists are immutable.
|
|
|
|
AttributeList addAttribute(LLVMContext &C, unsigned Index, Attribute A) const;
|
2015-12-02 07:58:49 +01:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \brief Add attributes to the attribute set at the given index.
|
|
|
|
/// Returns a new list because attribute lists are immutable.
|
2017-04-11 01:31:05 +02:00
|
|
|
AttributeList addAttributes(LLVMContext &C, unsigned Index,
|
|
|
|
const AttrBuilder &B) const;
|
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Add an argument attribute to the list. Returns a new list because
|
|
|
|
/// attribute lists are immutable.
|
|
|
|
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo,
|
|
|
|
Attribute::AttrKind Kind) const {
|
|
|
|
return addAttribute(C, ArgNo + FirstArgIndex, Kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add an argument attribute to the list. Returns a new list because
|
|
|
|
/// attribute lists are immutable.
|
|
|
|
AttributeList addParamAttribute(LLVMContext &C, unsigned ArgNo,
|
|
|
|
StringRef Kind,
|
|
|
|
StringRef Value = StringRef()) const {
|
|
|
|
return addAttribute(C, ArgNo + FirstArgIndex, Kind, Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add an attribute to the attribute list at the given arg indices. Returns a
|
|
|
|
/// new list because attribute lists are immutable.
|
|
|
|
AttributeList addParamAttribute(LLVMContext &C, ArrayRef<unsigned> ArgNos,
|
|
|
|
Attribute A) const;
|
|
|
|
|
|
|
|
/// Add an argument attribute to the list. Returns a new list because
|
|
|
|
/// attribute lists are immutable.
|
|
|
|
AttributeList addParamAttributes(LLVMContext &C, unsigned ArgNo,
|
|
|
|
const AttrBuilder &B) const {
|
|
|
|
return addAttributes(C, ArgNo + FirstArgIndex, B);
|
|
|
|
}
|
|
|
|
|
2012-12-19 23:42:22 +01:00
|
|
|
/// \brief Remove the specified attribute at the specified index from this
|
2017-05-31 21:23:09 +02:00
|
|
|
/// attribute list. Returns a new list because attribute lists are immutable.
|
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 removeAttribute(LLVMContext &C, unsigned Index,
|
|
|
|
Attribute::AttrKind Kind) const;
|
2013-01-23 01:45:55 +01:00
|
|
|
|
2016-06-15 19:50:39 +02:00
|
|
|
/// \brief Remove the specified attribute at the specified index from this
|
2017-05-31 21:23:09 +02:00
|
|
|
/// attribute list. Returns a new list because attribute lists are immutable.
|
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 removeAttribute(LLVMContext &C, unsigned Index,
|
|
|
|
StringRef Kind) const;
|
2016-06-15 19:50:39 +02:00
|
|
|
|
2013-01-23 01:45:55 +01:00
|
|
|
/// \brief Remove the specified attributes at the specified index from this
|
2017-05-31 21:23:09 +02:00
|
|
|
/// attribute list. Returns a new list because attribute lists are immutable.
|
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 removeAttributes(LLVMContext &C, unsigned Index,
|
2017-05-03 00:07:37 +02:00
|
|
|
const AttrBuilder &AttrsToRemove) const;
|
2015-05-07 01:19:43 +02:00
|
|
|
|
2017-04-11 01:31:05 +02:00
|
|
|
/// \brief Remove all attributes at the specified index from this
|
2017-05-31 21:23:09 +02:00
|
|
|
/// attribute list. Returns a new list because attribute lists are immutable.
|
2017-04-11 01:31:05 +02:00
|
|
|
AttributeList removeAttributes(LLVMContext &C, unsigned Index) const;
|
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \brief Remove the specified attribute at the specified arg index from this
|
|
|
|
/// attribute list. Returns a new list because attribute lists are immutable.
|
|
|
|
AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo,
|
|
|
|
Attribute::AttrKind Kind) const {
|
|
|
|
return removeAttribute(C, ArgNo + FirstArgIndex, Kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Remove the specified attribute at the specified arg index from this
|
|
|
|
/// attribute list. Returns a new list because attribute lists are immutable.
|
|
|
|
AttributeList removeParamAttribute(LLVMContext &C, unsigned ArgNo,
|
|
|
|
StringRef Kind) const {
|
|
|
|
return removeAttribute(C, ArgNo + FirstArgIndex, Kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Remove the specified attribute at the specified arg index from this
|
|
|
|
/// attribute list. Returns a new list because attribute lists are immutable.
|
|
|
|
AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo,
|
|
|
|
const AttrBuilder &AttrsToRemove) const {
|
|
|
|
return removeAttributes(C, ArgNo + FirstArgIndex, AttrsToRemove);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Remove all attributes at the specified arg index from this
|
|
|
|
/// attribute list. Returns a new list because attribute lists are immutable.
|
|
|
|
AttributeList removeParamAttributes(LLVMContext &C, unsigned ArgNo) const {
|
|
|
|
return removeAttributes(C, ArgNo + FirstArgIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \Brief Add the dereferenceable attribute to the attribute set at the given
|
|
|
|
/// index. Returns a new list because attribute lists are immutable.
|
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 addDereferenceableAttr(LLVMContext &C, unsigned Index,
|
|
|
|
uint64_t Bytes) const;
|
2015-02-14 20:37:54 +01:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \Brief Add the dereferenceable attribute to the attribute set at the given
|
|
|
|
/// arg index. Returns a new list because attribute lists are immutable.
|
|
|
|
AttributeList addDereferenceableParamAttr(LLVMContext &C, unsigned ArgNo,
|
|
|
|
uint64_t Bytes) const {
|
|
|
|
return addDereferenceableAttr(C, ArgNo + FirstArgIndex, Bytes);
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:29:50 +02:00
|
|
|
/// \brief Add the dereferenceable_or_null attribute to the attribute set at
|
2017-05-31 21:23:09 +02:00
|
|
|
/// the given index. Returns a new list because attribute lists are immutable.
|
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 addDereferenceableOrNullAttr(LLVMContext &C, unsigned Index,
|
|
|
|
uint64_t Bytes) const;
|
2015-04-16 22:29:50 +02:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \brief Add the dereferenceable_or_null attribute to the attribute set at
|
|
|
|
/// the given arg index. Returns a new list because attribute lists are
|
|
|
|
/// immutable.
|
|
|
|
AttributeList addDereferenceableOrNullParamAttr(LLVMContext &C,
|
|
|
|
unsigned ArgNo,
|
|
|
|
uint64_t Bytes) const {
|
|
|
|
return addDereferenceableOrNullAttr(C, ArgNo + FirstArgIndex, Bytes);
|
|
|
|
}
|
|
|
|
|
2016-04-12 03:05:35 +02:00
|
|
|
/// Add the allocsize attribute to the attribute set at the given index.
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Returns a new list because attribute lists are immutable.
|
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 addAllocSizeAttr(LLVMContext &C, unsigned Index,
|
|
|
|
unsigned ElemSizeArg,
|
|
|
|
const Optional<unsigned> &NumElemsArg);
|
2016-04-12 03:05:35 +02:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// Add the allocsize attribute to the attribute set at the given arg index.
|
|
|
|
/// Returns a new list because attribute lists are immutable.
|
|
|
|
AttributeList addAllocSizeParamAttr(LLVMContext &C, unsigned ArgNo,
|
|
|
|
unsigned ElemSizeArg,
|
|
|
|
const Optional<unsigned> &NumElemsArg) {
|
|
|
|
return addAllocSizeAttr(C, ArgNo + FirstArgIndex, ElemSizeArg, NumElemsArg);
|
|
|
|
}
|
|
|
|
|
2008-03-12 18:45:29 +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
|
|
|
// AttributeList Accessors
|
2008-03-12 18:45:29 +01:00
|
|
|
//===--------------------------------------------------------------------===//
|
2012-12-19 23:42:22 +01:00
|
|
|
|
2013-02-10 06:00:40 +01:00
|
|
|
/// \brief Retrieve the LLVM context.
|
|
|
|
LLVMContext &getContext() const;
|
|
|
|
|
2012-12-19 23:42:22 +01:00
|
|
|
/// \brief The attributes for the specified index are returned.
|
2017-04-12 02:38:00 +02:00
|
|
|
AttributeSet getAttributes(unsigned Index) const;
|
2017-04-11 01:31:05 +02:00
|
|
|
|
2017-04-14 01:12:13 +02:00
|
|
|
/// \brief The attributes for the argument or parameter at the given index are
|
|
|
|
/// returned.
|
|
|
|
AttributeSet getParamAttributes(unsigned ArgNo) const;
|
2008-09-27 00:53:05 +02:00
|
|
|
|
2012-12-19 23:42:22 +01:00
|
|
|
/// \brief The attributes for the ret value are returned.
|
2017-04-12 02:38:00 +02:00
|
|
|
AttributeSet getRetAttributes() const;
|
2008-09-27 00:53:05 +02:00
|
|
|
|
2012-12-19 23:42:22 +01:00
|
|
|
/// \brief The function attributes are returned.
|
2017-04-12 02:38:00 +02:00
|
|
|
AttributeSet getFnAttributes() const;
|
2010-01-04 08:16:12 +01:00
|
|
|
|
2012-12-30 11:32:01 +01:00
|
|
|
/// \brief Return true if the attribute exists at the given index.
|
2013-01-28 06:51:40 +01:00
|
|
|
bool hasAttribute(unsigned Index, Attribute::AttrKind Kind) const;
|
2012-12-30 11:32:01 +01:00
|
|
|
|
2013-02-13 09:42:21 +01:00
|
|
|
/// \brief Return true if the attribute exists at the given index.
|
|
|
|
bool hasAttribute(unsigned Index, StringRef Kind) const;
|
|
|
|
|
2012-12-30 11:32:01 +01:00
|
|
|
/// \brief Return true if attribute exists at the given index.
|
2013-01-28 06:51:40 +01:00
|
|
|
bool hasAttributes(unsigned Index) const;
|
2012-12-30 11:32:01 +01:00
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \brief Return true if the attribute exists for the given argument
|
|
|
|
bool hasParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
|
|
|
|
return hasAttribute(ArgNo + FirstArgIndex, Kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Return true if the attribute exists for the given argument
|
|
|
|
bool hasParamAttr(unsigned ArgNo, StringRef Kind) const {
|
|
|
|
return hasAttribute(ArgNo + FirstArgIndex, Kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Return true if attributes exists for the given argument
|
|
|
|
bool hasParamAttrs(unsigned ArgNo) const {
|
|
|
|
return hasAttributes(ArgNo + FirstArgIndex);
|
|
|
|
}
|
|
|
|
|
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
|
|
|
/// \brief Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
|
2016-01-29 23:25:19 +01:00
|
|
|
/// may be faster.
|
|
|
|
bool hasFnAttribute(Attribute::AttrKind Kind) const;
|
|
|
|
|
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
|
|
|
/// \brief Equivalent to hasAttribute(AttributeList::FunctionIndex, Kind) but
|
2016-09-09 06:50:38 +02:00
|
|
|
/// may be faster.
|
|
|
|
bool hasFnAttribute(StringRef Kind) const;
|
|
|
|
|
2017-05-03 20:17:31 +02:00
|
|
|
/// \brief Equivalent to hasAttribute(ArgNo + FirstArgIndex, Kind).
|
2017-04-14 01:12:13 +02:00
|
|
|
bool hasParamAttribute(unsigned ArgNo, Attribute::AttrKind Kind) const;
|
|
|
|
|
2013-01-29 01:34:06 +01:00
|
|
|
/// \brief Return true if the specified attribute is set for at least one
|
2016-07-11 01:01:32 +02:00
|
|
|
/// parameter or for the return value. If Index is not nullptr, the index
|
|
|
|
/// of a parameter with the specified attribute is provided.
|
|
|
|
bool hasAttrSomewhere(Attribute::AttrKind Kind,
|
|
|
|
unsigned *Index = nullptr) const;
|
2013-01-29 01:34:06 +01:00
|
|
|
|
2013-02-13 09:42:21 +01:00
|
|
|
/// \brief Return the attribute object that exists at the given index.
|
|
|
|
Attribute getAttribute(unsigned Index, Attribute::AttrKind Kind) const;
|
|
|
|
|
|
|
|
/// \brief Return the attribute object that exists at the given index.
|
|
|
|
Attribute getAttribute(unsigned Index, StringRef Kind) const;
|
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \brief Return the attribute object that exists at the arg index.
|
|
|
|
Attribute getParamAttr(unsigned ArgNo, Attribute::AttrKind Kind) const {
|
|
|
|
return getAttribute(ArgNo + FirstArgIndex, Kind);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Return the attribute object that exists at the given index.
|
|
|
|
Attribute getParamAttr(unsigned ArgNo, StringRef Kind) const {
|
|
|
|
return getAttribute(ArgNo + FirstArgIndex, Kind);
|
|
|
|
}
|
|
|
|
|
2017-04-28 22:34:27 +02:00
|
|
|
/// \brief Return the alignment of the return value.
|
|
|
|
unsigned getRetAlignment() const;
|
|
|
|
|
2013-01-28 06:23:28 +01:00
|
|
|
/// \brief Return the alignment for the specified function parameter.
|
2017-04-28 22:34:27 +02:00
|
|
|
unsigned getParamAlignment(unsigned ArgNo) const;
|
2013-01-26 00:09:36 +01:00
|
|
|
|
2012-12-30 11:32:01 +01:00
|
|
|
/// \brief Get the stack alignment.
|
2013-01-28 06:51:40 +01:00
|
|
|
unsigned getStackAlignment(unsigned Index) const;
|
2012-12-30 11:32:01 +01:00
|
|
|
|
2014-07-18 17:51:28 +02:00
|
|
|
/// \brief Get the number of dereferenceable bytes (or zero if unknown).
|
|
|
|
uint64_t getDereferenceableBytes(unsigned Index) const;
|
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \brief Get the number of dereferenceable bytes (or zero if unknown) of an
|
|
|
|
/// arg.
|
|
|
|
uint64_t getParamDereferenceableBytes(unsigned ArgNo) const {
|
|
|
|
return getDereferenceableBytes(ArgNo + FirstArgIndex);
|
|
|
|
}
|
|
|
|
|
2015-04-16 22:29:50 +02:00
|
|
|
/// \brief Get the number of dereferenceable_or_null bytes (or zero if
|
|
|
|
/// unknown).
|
|
|
|
uint64_t getDereferenceableOrNullBytes(unsigned Index) const;
|
|
|
|
|
2017-05-31 21:23:09 +02:00
|
|
|
/// \brief Get the number of dereferenceable_or_null bytes (or zero if
|
|
|
|
/// unknown) of an arg.
|
|
|
|
uint64_t getParamDereferenceableOrNullBytes(unsigned ArgNo) const {
|
|
|
|
return getDereferenceableOrNullBytes(ArgNo + FirstArgIndex);
|
|
|
|
}
|
|
|
|
|
2016-04-12 03:05:35 +02:00
|
|
|
/// Get the allocsize argument numbers (or pair(0, 0) if unknown).
|
|
|
|
std::pair<unsigned, Optional<unsigned>>
|
|
|
|
getAllocSizeArgs(unsigned Index) const;
|
|
|
|
|
2012-12-30 11:32:01 +01:00
|
|
|
/// \brief Return the attributes at the index as a string.
|
2013-05-01 15:07:03 +02:00
|
|
|
std::string getAsString(unsigned Index, bool InAttrGrp = false) const;
|
2012-12-30 11:32:01 +01:00
|
|
|
|
[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
llvm-svn: 303654
2017-05-23 19:01:48 +02:00
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
// AttributeList Introspection
|
|
|
|
//===--------------------------------------------------------------------===//
|
|
|
|
|
2017-06-20 00:05:08 +02: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
llvm-svn: 303654
2017-05-23 19:01:48 +02:00
|
|
|
iterator begin() const;
|
|
|
|
iterator end() const;
|
|
|
|
|
|
|
|
unsigned getNumAttrSets() const;
|
2013-02-01 00:53:05 +01:00
|
|
|
|
[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
llvm-svn: 303654
2017-05-23 19:01:48 +02:00
|
|
|
/// Use these to iterate over the valid attribute indices.
|
|
|
|
unsigned index_begin() const { return AttributeList::FunctionIndex; }
|
|
|
|
unsigned index_end() const { return getNumAttrSets() - 1; }
|
2013-02-01 00:53:05 +01:00
|
|
|
|
2008-03-13 05:33:03 +01:00
|
|
|
/// operator==/!= - Provide equality predicates.
|
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
|
|
|
bool operator==(const AttributeList &RHS) const { return pImpl == RHS.pImpl; }
|
|
|
|
bool operator!=(const AttributeList &RHS) const { return pImpl != RHS.pImpl; }
|
2010-01-04 08:16:12 +01:00
|
|
|
|
2012-12-19 23:42:22 +01:00
|
|
|
/// \brief Return a raw pointer that uniquely identifies this attribute list.
|
2008-03-12 18:45:29 +01:00
|
|
|
void *getRawPointer() const {
|
2013-01-27 22:23:46 +01:00
|
|
|
return pImpl;
|
2008-03-12 18:45:29 +01:00
|
|
|
}
|
2010-01-04 08:16:12 +01:00
|
|
|
|
2012-12-19 23:42:22 +01:00
|
|
|
/// \brief Return true if there are no attributes.
|
[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
llvm-svn: 303654
2017-05-23 19:01:48 +02:00
|
|
|
bool isEmpty() const { return pImpl == nullptr; }
|
2013-01-26 00:09:36 +01:00
|
|
|
|
2012-10-16 08:10:45 +02:00
|
|
|
void dump() const;
|
2008-03-12 18:45:29 +01:00
|
|
|
};
|
2007-04-22 07:46:44 +02:00
|
|
|
|
2013-01-29 01:34:06 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \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
|
|
|
/// \brief Provide DenseMapInfo for AttributeList.
|
|
|
|
template <> struct DenseMapInfo<AttributeList> {
|
2018-03-30 02:47:31 +02:00
|
|
|
static AttributeList getEmptyKey() {
|
|
|
|
auto Val = static_cast<uintptr_t>(-1);
|
2013-02-09 16:42:51 +01:00
|
|
|
Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
|
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
|
|
|
return AttributeList(reinterpret_cast<AttributeListImpl *>(Val));
|
2013-01-29 01:34:06 +01:00
|
|
|
}
|
2017-02-17 01:00:09 +01:00
|
|
|
|
2018-03-30 02:47:31 +02:00
|
|
|
static AttributeList getTombstoneKey() {
|
|
|
|
auto Val = static_cast<uintptr_t>(-2);
|
2013-02-09 16:42:51 +01:00
|
|
|
Val <<= PointerLikeTypeTraits<void*>::NumLowBitsAvailable;
|
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
|
|
|
return AttributeList(reinterpret_cast<AttributeListImpl *>(Val));
|
2013-01-29 01:34:06 +01:00
|
|
|
}
|
2017-02-17 01:00:09 +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
|
|
|
static unsigned getHashValue(AttributeList AS) {
|
2013-02-09 16:42:51 +01:00
|
|
|
return (unsigned((uintptr_t)AS.pImpl) >> 4) ^
|
|
|
|
(unsigned((uintptr_t)AS.pImpl) >> 9);
|
2013-01-29 01:34:06 +01:00
|
|
|
}
|
2017-02-17 01:00:09 +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
|
|
|
static bool isEqual(AttributeList LHS, AttributeList RHS) {
|
|
|
|
return LHS == RHS;
|
|
|
|
}
|
2013-01-29 01:34:06 +01:00
|
|
|
};
|
|
|
|
|
2013-01-07 09:24:35 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
|
|
|
/// \brief This class is used in conjunction with the Attribute::get method to
|
|
|
|
/// create an Attribute object. The object itself is uniquified. The Builder's
|
|
|
|
/// value, however, is not. So this can be used as a quick way to test for
|
|
|
|
/// equality, presence of attributes, etc.
|
|
|
|
class AttrBuilder {
|
2013-02-18 13:09:51 +01:00
|
|
|
std::bitset<Attribute::EndAttrKinds> Attrs;
|
2013-02-05 09:09:32 +01:00
|
|
|
std::map<std::string, std::string> TargetDepAttrs;
|
2017-02-17 01:00:09 +01:00
|
|
|
uint64_t Alignment = 0;
|
|
|
|
uint64_t StackAlignment = 0;
|
|
|
|
uint64_t DerefBytes = 0;
|
|
|
|
uint64_t DerefOrNullBytes = 0;
|
|
|
|
uint64_t AllocSizeArgs = 0;
|
2015-09-22 13:14:39 +02:00
|
|
|
|
2013-01-07 09:24:35 +01:00
|
|
|
public:
|
2017-02-17 01:00:09 +01:00
|
|
|
AttrBuilder() = default;
|
2018-03-30 02:47:31 +02:00
|
|
|
|
2017-02-17 01:00:09 +01:00
|
|
|
AttrBuilder(const Attribute &A) {
|
2013-02-01 00:38:01 +01:00
|
|
|
addAttribute(A);
|
2013-01-07 09:24:35 +01:00
|
|
|
}
|
2018-03-30 02:47:31 +02: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
|
|
|
AttrBuilder(AttributeList AS, unsigned Idx);
|
2017-04-12 02:38:00 +02:00
|
|
|
AttrBuilder(AttributeSet AS);
|
2013-01-07 09:24:35 +01:00
|
|
|
|
|
|
|
void clear();
|
|
|
|
|
|
|
|
/// \brief Add an attribute to the builder.
|
|
|
|
AttrBuilder &addAttribute(Attribute::AttrKind Val);
|
|
|
|
|
2013-02-01 00:38:01 +01:00
|
|
|
/// \brief Add the Attribute object to the builder.
|
|
|
|
AttrBuilder &addAttribute(Attribute A);
|
|
|
|
|
2013-02-05 09:09:32 +01:00
|
|
|
/// \brief Add the target-dependent attribute to the builder.
|
2013-02-13 00:14:31 +01:00
|
|
|
AttrBuilder &addAttribute(StringRef A, StringRef V = StringRef());
|
2013-02-05 09:09:32 +01:00
|
|
|
|
2013-01-07 09:24:35 +01:00
|
|
|
/// \brief Remove an attribute from the builder.
|
|
|
|
AttrBuilder &removeAttribute(Attribute::AttrKind Val);
|
|
|
|
|
2013-01-28 06:23:28 +01:00
|
|
|
/// \brief Remove the attributes from the builder.
|
2017-04-11 01:31:05 +02:00
|
|
|
AttrBuilder &removeAttributes(AttributeList A, uint64_t WithoutIndex);
|
2013-01-07 09:24:35 +01:00
|
|
|
|
2013-02-05 09:09:32 +01:00
|
|
|
/// \brief Remove the target-dependent attribute to the builder.
|
|
|
|
AttrBuilder &removeAttribute(StringRef A);
|
|
|
|
|
2013-02-06 02:16:00 +01:00
|
|
|
/// \brief Add the attributes from the builder.
|
|
|
|
AttrBuilder &merge(const AttrBuilder &B);
|
|
|
|
|
2015-05-07 01:19:43 +02:00
|
|
|
/// \brief Remove the attributes from the builder.
|
|
|
|
AttrBuilder &remove(const AttrBuilder &B);
|
|
|
|
|
2015-05-07 12:18:56 +02:00
|
|
|
/// \brief Return true if the builder has any attribute that's in the
|
2015-05-07 01:19:43 +02:00
|
|
|
/// specified builder.
|
|
|
|
bool overlaps(const AttrBuilder &B) const;
|
|
|
|
|
2013-01-07 09:24:35 +01:00
|
|
|
/// \brief Return true if the builder has the specified attribute.
|
2013-02-16 20:13:18 +01:00
|
|
|
bool contains(Attribute::AttrKind A) const {
|
2013-02-18 13:09:51 +01:00
|
|
|
assert((unsigned)A < Attribute::EndAttrKinds && "Attribute out of range!");
|
|
|
|
return Attrs[A];
|
2013-02-16 20:13:18 +01:00
|
|
|
}
|
2013-01-07 09:24:35 +01:00
|
|
|
|
2013-02-06 02:33:42 +01:00
|
|
|
/// \brief Return true if the builder has the specified target-dependent
|
|
|
|
/// attribute.
|
|
|
|
bool contains(StringRef A) const;
|
|
|
|
|
2013-01-07 09:24:35 +01:00
|
|
|
/// \brief Return true if the builder has IR-level attributes.
|
|
|
|
bool hasAttributes() const;
|
|
|
|
|
|
|
|
/// \brief Return true if the builder has any attribute that's in the
|
|
|
|
/// specified attribute.
|
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
|
|
|
bool hasAttributes(AttributeList A, uint64_t Index) const;
|
2013-01-07 09:24:35 +01:00
|
|
|
|
|
|
|
/// \brief Return true if the builder has an alignment attribute.
|
|
|
|
bool hasAlignmentAttr() const;
|
|
|
|
|
|
|
|
/// \brief Retrieve the alignment attribute, if it exists.
|
|
|
|
uint64_t getAlignment() const { return Alignment; }
|
|
|
|
|
|
|
|
/// \brief Retrieve the stack alignment attribute, if it exists.
|
|
|
|
uint64_t getStackAlignment() const { return StackAlignment; }
|
|
|
|
|
2015-09-22 13:14:12 +02:00
|
|
|
/// \brief Retrieve the number of dereferenceable bytes, if the
|
|
|
|
/// dereferenceable attribute exists (zero is returned otherwise).
|
2014-07-18 17:51:28 +02:00
|
|
|
uint64_t getDereferenceableBytes() const { return DerefBytes; }
|
|
|
|
|
2015-04-16 22:29:50 +02:00
|
|
|
/// \brief Retrieve the number of dereferenceable_or_null bytes, if the
|
|
|
|
/// dereferenceable_or_null attribute exists (zero is returned otherwise).
|
|
|
|
uint64_t getDereferenceableOrNullBytes() const { return DerefOrNullBytes; }
|
|
|
|
|
2016-04-12 03:05:35 +02:00
|
|
|
/// Retrieve the allocsize args, if the allocsize attribute exists. If it
|
|
|
|
/// doesn't exist, pair(0, 0) is returned.
|
|
|
|
std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
|
|
|
|
|
2013-01-07 09:24:35 +01:00
|
|
|
/// \brief This turns an int alignment (which must be a power of 2) into the
|
|
|
|
/// form used internally in Attribute.
|
|
|
|
AttrBuilder &addAlignmentAttr(unsigned Align);
|
|
|
|
|
|
|
|
/// \brief This turns an int stack alignment (which must be a power of 2) into
|
|
|
|
/// the form used internally in Attribute.
|
|
|
|
AttrBuilder &addStackAlignmentAttr(unsigned Align);
|
|
|
|
|
2014-07-18 17:51:28 +02:00
|
|
|
/// \brief This turns the number of dereferenceable bytes into the form used
|
|
|
|
/// internally in Attribute.
|
|
|
|
AttrBuilder &addDereferenceableAttr(uint64_t Bytes);
|
|
|
|
|
2015-04-16 22:29:50 +02:00
|
|
|
/// \brief This turns the number of dereferenceable_or_null bytes into the
|
|
|
|
/// form used internally in Attribute.
|
|
|
|
AttrBuilder &addDereferenceableOrNullAttr(uint64_t Bytes);
|
|
|
|
|
2016-04-12 03:05:35 +02:00
|
|
|
/// This turns one (or two) ints into the form used internally in Attribute.
|
|
|
|
AttrBuilder &addAllocSizeAttr(unsigned ElemSizeArg,
|
|
|
|
const Optional<unsigned> &NumElemsArg);
|
|
|
|
|
|
|
|
/// Add an allocsize attribute, using the representation returned by
|
|
|
|
/// Attribute.getIntValue().
|
|
|
|
AttrBuilder &addAllocSizeAttrFromRawRepr(uint64_t RawAllocSizeRepr);
|
|
|
|
|
2013-02-16 20:13:18 +01:00
|
|
|
/// \brief Return true if the builder contains no target-independent
|
|
|
|
/// attributes.
|
2013-02-18 13:09:51 +01:00
|
|
|
bool empty() const { return Attrs.none(); }
|
2013-02-10 11:12:06 +01:00
|
|
|
|
2013-02-06 00:48:36 +01:00
|
|
|
// Iterators for target-dependent attributes.
|
2017-05-06 00:30:37 +02:00
|
|
|
using td_type = std::pair<std::string, std::string>;
|
|
|
|
using td_iterator = std::map<std::string, std::string>::iterator;
|
|
|
|
using td_const_iterator = std::map<std::string, std::string>::const_iterator;
|
|
|
|
using td_range = iterator_range<td_iterator>;
|
|
|
|
using td_const_range = iterator_range<td_const_iterator>;
|
2013-02-06 00:48:36 +01:00
|
|
|
|
2018-03-30 02:47:31 +02:00
|
|
|
td_iterator td_begin() { return TargetDepAttrs.begin(); }
|
|
|
|
td_iterator td_end() { return TargetDepAttrs.end(); }
|
2013-02-06 00:48:36 +01:00
|
|
|
|
|
|
|
td_const_iterator td_begin() const { return TargetDepAttrs.begin(); }
|
2018-03-30 02:47:31 +02:00
|
|
|
td_const_iterator td_end() const { return TargetDepAttrs.end(); }
|
2013-02-06 00:48:36 +01:00
|
|
|
|
2014-05-04 01:00:35 +02:00
|
|
|
td_range td_attrs() { return td_range(td_begin(), td_end()); }
|
2018-03-30 02:47:31 +02:00
|
|
|
|
2014-05-04 01:00:35 +02:00
|
|
|
td_const_range td_attrs() const {
|
|
|
|
return td_const_range(td_begin(), td_end());
|
|
|
|
}
|
|
|
|
|
2018-03-30 02:47:31 +02:00
|
|
|
bool td_empty() const { return TargetDepAttrs.empty(); }
|
2013-02-10 11:12:06 +01:00
|
|
|
|
2013-01-07 09:24:35 +01:00
|
|
|
bool operator==(const AttrBuilder &B);
|
|
|
|
bool operator!=(const AttrBuilder &B) {
|
|
|
|
return !(*this == B);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-26 00:09:36 +01:00
|
|
|
namespace AttributeFuncs {
|
|
|
|
|
|
|
|
/// \brief Which attributes cannot be applied to a type.
|
2015-08-02 00:20:21 +02:00
|
|
|
AttrBuilder typeIncompatible(Type *Ty);
|
2013-01-26 00:09:36 +01:00
|
|
|
|
2015-12-23 00:57:37 +01:00
|
|
|
/// \returns Return true if the two functions have compatible target-independent
|
|
|
|
/// attributes for inlining purposes.
|
|
|
|
bool areInlineCompatible(const Function &Caller, const Function &Callee);
|
|
|
|
|
|
|
|
/// \brief Merge caller's and callee's attributes.
|
|
|
|
void mergeAttributesForInlining(Function &Caller, const Function &Callee);
|
|
|
|
|
2017-06-20 00:05:08 +02:00
|
|
|
} // end namespace AttributeFuncs
|
2013-01-26 00:09:36 +01:00
|
|
|
|
2017-06-20 00:05:08 +02:00
|
|
|
} // end namespace llvm
|
2007-04-08 16:46:50 +02:00
|
|
|
|
2017-02-17 01:00:09 +01:00
|
|
|
#endif // LLVM_IR_ATTRIBUTES_H
|