2017-05-15 23:57:41 +02:00
|
|
|
//===- AttributeImpl.h - Attribute Internals --------------------*- C++ -*-===//
|
2012-09-26 23:07:29 +02:00
|
|
|
//
|
2019-01-19 09:50:56 +01:00
|
|
|
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
// See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2012-09-26 23:07:29 +02:00
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
2012-12-20 22:28:43 +01:00
|
|
|
///
|
|
|
|
/// \file
|
2018-05-01 17:54:18 +02:00
|
|
|
/// This file defines various helper methods and classes used by
|
2012-12-20 22:28:43 +01:00
|
|
|
/// LLVMContextImpl for creating and managing attributes.
|
|
|
|
///
|
2012-09-26 23:07:29 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
2014-08-13 18:26:38 +02:00
|
|
|
#ifndef LLVM_LIB_IR_ATTRIBUTEIMPL_H
|
|
|
|
#define LLVM_LIB_IR_ATTRIBUTEIMPL_H
|
2012-09-26 23:07:29 +02:00
|
|
|
|
2016-12-07 23:06:02 +01:00
|
|
|
#include "llvm/ADT/ArrayRef.h"
|
2020-04-25 12:21:21 +02:00
|
|
|
#include "llvm/ADT/DenseMap.h"
|
2012-09-26 23:07:29 +02:00
|
|
|
#include "llvm/ADT/FoldingSet.h"
|
2016-12-07 23:06:02 +01:00
|
|
|
#include "llvm/ADT/StringRef.h"
|
2013-01-02 12:36:10 +01:00
|
|
|
#include "llvm/IR/Attributes.h"
|
2016-12-07 23:06:02 +01:00
|
|
|
#include "llvm/Support/TrailingObjects.h"
|
|
|
|
#include <cassert>
|
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2016-01-29 23:35:29 +01:00
|
|
|
#include <string>
|
2016-12-07 23:06:02 +01:00
|
|
|
#include <utility>
|
2012-09-26 23:07:29 +02:00
|
|
|
|
|
|
|
namespace llvm {
|
|
|
|
|
2012-12-20 00:55:43 +01:00
|
|
|
class LLVMContext;
|
2019-05-30 20:48:23 +02:00
|
|
|
class Type;
|
2012-12-20 00:55:43 +01:00
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
2018-05-01 17:54:18 +02:00
|
|
|
/// This class represents a single, uniqued attribute. That attribute
|
2013-07-11 14:13:16 +02:00
|
|
|
/// could be a single enum, a tuple, or a string.
|
2013-09-11 20:05:11 +02:00
|
|
|
class AttributeImpl : public FoldingSetNode {
|
2013-07-11 14:13:16 +02:00
|
|
|
unsigned char KindID; ///< Holds the AttrEntryKind of the attribute
|
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
protected:
|
|
|
|
enum AttrEntryKind {
|
|
|
|
EnumAttrEntry,
|
2014-07-18 08:51:55 +02:00
|
|
|
IntAttrEntry,
|
2019-05-30 20:48:23 +02:00
|
|
|
StringAttrEntry,
|
|
|
|
TypeAttrEntry,
|
2013-02-05 23:37:24 +01:00
|
|
|
};
|
|
|
|
|
2013-07-11 14:13:16 +02:00
|
|
|
AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {}
|
2013-01-27 22:38:03 +01:00
|
|
|
|
2012-09-26 23:07:29 +02:00
|
|
|
public:
|
2016-12-07 23:06:02 +01:00
|
|
|
// AttributesImpl is uniqued, these should not be available.
|
|
|
|
AttributeImpl(const AttributeImpl &) = delete;
|
|
|
|
AttributeImpl &operator=(const AttributeImpl &) = delete;
|
|
|
|
|
2013-07-11 14:13:16 +02:00
|
|
|
bool isEnumAttribute() const { return KindID == EnumAttrEntry; }
|
2014-07-18 08:51:55 +02:00
|
|
|
bool isIntAttribute() const { return KindID == IntAttrEntry; }
|
2013-07-11 14:13:16 +02:00
|
|
|
bool isStringAttribute() const { return KindID == StringAttrEntry; }
|
2019-05-30 20:48:23 +02:00
|
|
|
bool isTypeAttribute() const { return KindID == TypeAttrEntry; }
|
2012-10-08 23:47:17 +02:00
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
bool hasAttribute(Attribute::AttrKind A) const;
|
|
|
|
bool hasAttribute(StringRef Kind) const;
|
2012-10-08 23:47:17 +02:00
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
Attribute::AttrKind getKindAsEnum() const;
|
|
|
|
uint64_t getValueAsInt() const;
|
2012-12-30 02:38:39 +01:00
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
StringRef getKindAsString() const;
|
|
|
|
StringRef getValueAsString() const;
|
2012-12-30 02:38:39 +01:00
|
|
|
|
2019-05-30 20:48:23 +02:00
|
|
|
Type *getValueAsType() const;
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Used when sorting the attributes.
|
2013-01-24 01:06:56 +01:00
|
|
|
bool operator<(const AttributeImpl &AI) const;
|
|
|
|
|
2012-09-26 23:07:29 +02:00
|
|
|
void Profile(FoldingSetNodeID &ID) const {
|
2013-02-05 23:37:24 +01:00
|
|
|
if (isEnumAttribute())
|
2019-05-30 20:48:23 +02:00
|
|
|
Profile(ID, getKindAsEnum(), static_cast<uint64_t>(0));
|
2014-07-18 08:51:55 +02:00
|
|
|
else if (isIntAttribute())
|
2013-02-05 23:37:24 +01:00
|
|
|
Profile(ID, getKindAsEnum(), getValueAsInt());
|
2019-05-30 20:48:23 +02:00
|
|
|
else if (isStringAttribute())
|
2019-05-29 22:46:38 +02:00
|
|
|
Profile(ID, getKindAsString(), getValueAsString());
|
2019-05-30 20:48:23 +02:00
|
|
|
else
|
|
|
|
Profile(ID, getKindAsEnum(), getValueAsType());
|
2013-02-05 23:37:24 +01:00
|
|
|
}
|
2017-05-15 23:57:41 +02:00
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
|
|
|
|
uint64_t Val) {
|
|
|
|
ID.AddInteger(Kind);
|
|
|
|
if (Val) ID.AddInteger(Val);
|
2012-09-26 23:07:29 +02:00
|
|
|
}
|
2017-05-15 23:57:41 +02:00
|
|
|
|
2013-02-05 23:37:24 +01:00
|
|
|
static void Profile(FoldingSetNodeID &ID, StringRef Kind, StringRef Values) {
|
|
|
|
ID.AddString(Kind);
|
2013-02-28 22:17:03 +01:00
|
|
|
if (!Values.empty()) ID.AddString(Values);
|
2013-01-29 01:34:06 +01:00
|
|
|
}
|
2019-05-30 20:48:23 +02:00
|
|
|
|
|
|
|
static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
|
|
|
|
Type *Ty) {
|
|
|
|
ID.AddInteger(Kind);
|
|
|
|
ID.AddPointer(Ty);
|
|
|
|
}
|
2012-09-26 23:07:29 +02:00
|
|
|
};
|
|
|
|
|
2020-05-01 14:12:17 +02:00
|
|
|
static_assert(std::is_trivially_destructible<AttributeImpl>::value,
|
|
|
|
"AttributeImpl should be trivially destructible");
|
|
|
|
|
2013-07-11 14:13:16 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
2018-05-01 17:54:18 +02:00
|
|
|
/// A set of classes that contain the value of the
|
2013-07-11 14:13:16 +02:00
|
|
|
/// 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 20:05:11 +02:00
|
|
|
class EnumAttributeImpl : public AttributeImpl {
|
2013-07-11 14:13:16 +02:00
|
|
|
Attribute::AttrKind Kind;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
EnumAttributeImpl(AttrEntryKind ID, Attribute::AttrKind Kind)
|
|
|
|
: AttributeImpl(ID), Kind(Kind) {}
|
|
|
|
|
|
|
|
public:
|
|
|
|
EnumAttributeImpl(Attribute::AttrKind Kind)
|
2020-08-28 22:02:42 +02:00
|
|
|
: AttributeImpl(EnumAttrEntry), Kind(Kind) {
|
|
|
|
assert(Kind != Attribute::AttrKind::None &&
|
|
|
|
"Can't create a None attribute!");
|
|
|
|
}
|
2013-07-11 14:13:16 +02:00
|
|
|
|
|
|
|
Attribute::AttrKind getEnumKind() const { return Kind; }
|
|
|
|
};
|
|
|
|
|
2014-07-18 08:51:55 +02:00
|
|
|
class IntAttributeImpl : public EnumAttributeImpl {
|
|
|
|
uint64_t Val;
|
2013-07-11 14:13:16 +02:00
|
|
|
|
|
|
|
public:
|
2014-07-18 08:51:55 +02:00
|
|
|
IntAttributeImpl(Attribute::AttrKind Kind, uint64_t Val)
|
|
|
|
: EnumAttributeImpl(IntAttrEntry, Kind), Val(Val) {
|
2020-02-02 14:47:00 +01:00
|
|
|
assert(Attribute::doesAttrKindHaveArgument(Kind) &&
|
2015-04-16 22:29:50 +02:00
|
|
|
"Wrong kind for int attribute!");
|
2013-07-11 14:13:16 +02:00
|
|
|
}
|
|
|
|
|
2014-07-18 08:51:55 +02:00
|
|
|
uint64_t getValue() const { return Val; }
|
2013-07-11 14:13:16 +02:00
|
|
|
};
|
|
|
|
|
2020-05-01 14:12:17 +02:00
|
|
|
class StringAttributeImpl final
|
|
|
|
: public AttributeImpl,
|
|
|
|
private TrailingObjects<StringAttributeImpl, char> {
|
|
|
|
friend TrailingObjects;
|
2017-06-20 00:05:08 +02:00
|
|
|
|
2020-05-01 14:12:17 +02:00
|
|
|
unsigned KindSize;
|
|
|
|
unsigned ValSize;
|
|
|
|
size_t numTrailingObjects(OverloadToken<char>) const {
|
|
|
|
return KindSize + 1 + ValSize + 1;
|
|
|
|
}
|
2013-07-11 14:13:16 +02:00
|
|
|
|
|
|
|
public:
|
|
|
|
StringAttributeImpl(StringRef Kind, StringRef Val = StringRef())
|
2020-05-01 14:12:17 +02:00
|
|
|
: AttributeImpl(StringAttrEntry), KindSize(Kind.size()),
|
|
|
|
ValSize(Val.size()) {
|
|
|
|
char *TrailingString = getTrailingObjects<char>();
|
|
|
|
// Some users rely on zero-termination.
|
|
|
|
llvm::copy(Kind, TrailingString);
|
|
|
|
TrailingString[KindSize] = '\0';
|
|
|
|
llvm::copy(Val, &TrailingString[KindSize + 1]);
|
|
|
|
TrailingString[KindSize + 1 + ValSize] = '\0';
|
|
|
|
}
|
2013-07-11 14:13:16 +02:00
|
|
|
|
2020-05-01 14:12:17 +02:00
|
|
|
StringRef getStringKind() const {
|
|
|
|
return StringRef(getTrailingObjects<char>(), KindSize);
|
|
|
|
}
|
|
|
|
StringRef getStringValue() const {
|
|
|
|
return StringRef(getTrailingObjects<char>() + KindSize + 1, ValSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t totalSizeToAlloc(StringRef Kind, StringRef Val) {
|
|
|
|
return TrailingObjects::totalSizeToAlloc<char>(Kind.size() + 1 +
|
|
|
|
Val.size() + 1);
|
|
|
|
}
|
2013-07-11 14:13:16 +02:00
|
|
|
};
|
|
|
|
|
2019-05-30 20:48:23 +02:00
|
|
|
class TypeAttributeImpl : public EnumAttributeImpl {
|
|
|
|
Type *Ty;
|
|
|
|
|
|
|
|
public:
|
|
|
|
TypeAttributeImpl(Attribute::AttrKind Kind, Type *Ty)
|
|
|
|
: EnumAttributeImpl(TypeAttrEntry, Kind), Ty(Ty) {}
|
|
|
|
|
|
|
|
Type *getTypeValue() const { return Ty; }
|
|
|
|
};
|
|
|
|
|
2020-06-14 23:46:18 +02:00
|
|
|
class AttributeBitSet {
|
|
|
|
/// Bitset with a bit for each available attribute Attribute::AttrKind.
|
|
|
|
uint8_t AvailableAttrs[12] = {};
|
|
|
|
static_assert(Attribute::EndAttrKinds <= sizeof(AvailableAttrs) * CHAR_BIT,
|
|
|
|
"Too many attributes");
|
|
|
|
|
|
|
|
public:
|
|
|
|
bool hasAttribute(Attribute::AttrKind Kind) const {
|
2020-06-23 22:18:56 +02:00
|
|
|
return AvailableAttrs[Kind / 8] & (1 << (Kind % 8));
|
2020-06-14 23:46:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void addAttribute(Attribute::AttrKind Kind) {
|
2020-06-23 22:18:56 +02:00
|
|
|
AvailableAttrs[Kind / 8] |= 1 << (Kind % 8);
|
2020-06-14 23:46:18 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-04-12 02:38:00 +02:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
2018-05-01 17:54:18 +02:00
|
|
|
/// This class represents a group of attributes that apply to one
|
2017-04-12 02:38:00 +02:00
|
|
|
/// element: function, return type, or parameter.
|
|
|
|
class AttributeSetNode final
|
|
|
|
: public FoldingSetNode,
|
|
|
|
private TrailingObjects<AttributeSetNode, Attribute> {
|
|
|
|
friend TrailingObjects;
|
|
|
|
|
|
|
|
unsigned NumAttrs; ///< Number of attributes in this node.
|
2020-06-14 23:46:18 +02:00
|
|
|
AttributeBitSet AvailableAttrs; ///< Available enum attributes.
|
2017-04-12 02:38:00 +02:00
|
|
|
|
2020-04-25 12:21:21 +02:00
|
|
|
DenseMap<StringRef, Attribute> StringAttrs;
|
|
|
|
|
2017-04-12 02:38:00 +02:00
|
|
|
AttributeSetNode(ArrayRef<Attribute> Attrs);
|
|
|
|
|
2020-04-26 16:52:53 +02:00
|
|
|
static AttributeSetNode *getSorted(LLVMContext &C,
|
|
|
|
ArrayRef<Attribute> SortedAttrs);
|
2020-04-26 20:03:29 +02:00
|
|
|
Optional<Attribute> findEnumAttribute(Attribute::AttrKind Kind) const;
|
2020-04-26 16:52:53 +02:00
|
|
|
|
2017-04-12 02:38:00 +02:00
|
|
|
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);
|
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Return the number of attributes this AttributeList contains.
|
2017-04-12 02:38:00 +02:00
|
|
|
unsigned getNumAttributes() const { return NumAttrs; }
|
|
|
|
|
|
|
|
bool hasAttribute(Attribute::AttrKind Kind) const {
|
2020-06-14 23:46:18 +02:00
|
|
|
return AvailableAttrs.hasAttribute(Kind);
|
2017-04-12 02:38:00 +02:00
|
|
|
}
|
|
|
|
bool hasAttribute(StringRef Kind) const;
|
|
|
|
bool hasAttributes() const { return NumAttrs != 0; }
|
|
|
|
|
|
|
|
Attribute getAttribute(Attribute::AttrKind Kind) const;
|
|
|
|
Attribute getAttribute(StringRef Kind) const;
|
|
|
|
|
2019-10-22 11:51:06 +02:00
|
|
|
MaybeAlign getAlignment() const;
|
|
|
|
MaybeAlign getStackAlignment() const;
|
2017-04-12 02:38:00 +02:00
|
|
|
uint64_t getDereferenceableBytes() const;
|
|
|
|
uint64_t getDereferenceableOrNullBytes() const;
|
|
|
|
std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
|
2021-03-03 14:53:30 +01:00
|
|
|
std::pair<unsigned, unsigned> getVScaleRangeArgs() const;
|
2017-04-12 02:38:00 +02:00
|
|
|
std::string getAsString(bool InAttrGrp) const;
|
2019-05-30 20:48:23 +02:00
|
|
|
Type *getByValType() const;
|
2020-09-29 15:33:55 +02:00
|
|
|
Type *getStructRetType() const;
|
IR: Define byref parameter attribute
This allows tracking the in-memory type of a pointer argument to a
function for ABI purposes. This is essentially a stripped down version
of byval to remove some of the stack-copy implications in its
definition.
This includes the base IR changes, and some tests for places where it
should be treated similarly to byval. Codegen support will be in a
future patch.
My original attempt at solving some of these problems was to repurpose
byval with a different address space from the stack. However, it is
technically permitted for the callee to introduce a write to the
argument, although nothing does this in reality. There is also talk of
removing and replacing the byval attribute, so a new attribute would
need to take its place anyway.
This is intended avoid some optimization issues with the current
handling of aggregate arguments, as well as fixes inflexibilty in how
frontends can specify the kernel ABI. The most honest representation
of the amdgpu_kernel convention is to expose all kernel arguments as
loads from constant memory. Today, these are raw, SSA Argument values
and codegen is responsible for turning these into loads.
Background:
There currently isn't a satisfactory way to represent how arguments
for the amdgpu_kernel calling convention are passed. In reality,
arguments are passed in a single, flat, constant memory buffer
implicitly passed to the function. It is also illegal to call this
function in the IR, and this is only ever invoked by a driver of some
kind.
It does not make sense to have a stack passed parameter in this
context as is implied by byval. It is never valid to write to the
kernel arguments, as this would corrupt the inputs seen by other
dispatches of the kernel. These argumets are also not in the same
address space as the stack, so a copy is needed to an alloca. From a
source C-like language, the kernel parameters are invisible.
Semantically, a copy is always required from the constant argument
memory to a mutable variable.
The current clang calling convention lowering emits raw values,
including aggregates into the function argument list, since using
byval would not make sense. This has some unfortunate consequences for
the optimizer. In the aggregate case, we end up with an aggregate
store to alloca, which both SROA and instcombine turn into a store of
each aggregate field. The optimizer never pieces this back together to
see that this is really just a copy from constant memory, so we end up
stuck with expensive stack usage.
This also means the backend dictates the alignment of arguments, and
arbitrarily picks the LLVM IR ABI type alignment. By allowing an
explicit alignment, frontends can make better decisions. For example,
there's real no advantage to an aligment higher than 4, so a frontend
could choose to compact the argument layout. Similarly, there is a
high penalty to using an alignment lower than 4, so a frontend could
opt into more padding for small arguments.
Another design consideration is when it is appropriate to expose the
fact that these arguments are all really passed in adjacent
memory. Currently we have a late IR optimization pass in codegen to
rewrite the kernel argument values into explicit loads to enable
vectorization. In most programs, unrelated argument loads can be
merged together. However, exposing this property directly from the
frontend has some disadvantages. We still need a way to track the
original argument sizes and alignments to report to the driver. I find
using some side-channel, metadata mechanism to track this
unappealing. If the kernel arguments were exposed as a single buffer
to begin with, alias analysis would be unaware that the padding bits
betewen arguments are meaningless. Another family of problems is there
are still some gaps in replacing all of the available parameter
attributes with metadata equivalents once lowered to loads.
The immediate plan is to start using this new attribute to handle all
aggregate argumets for kernels. Long term, it makes sense to migrate
all kernel arguments, including scalars, to be passed indirectly in
the same manner.
Additional context is in D79744.
2020-06-05 22:58:47 +02:00
|
|
|
Type *getByRefType() const;
|
2020-02-14 23:16:53 +01:00
|
|
|
Type *getPreallocatedType() const;
|
2021-03-06 19:23:57 +01:00
|
|
|
Type *getInAllocaType() const;
|
2017-04-12 02:38:00 +02:00
|
|
|
|
2017-05-15 23:57:41 +02:00
|
|
|
using iterator = const Attribute *;
|
|
|
|
|
2017-04-12 02:38:00 +02: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 23:57:41 +02:00
|
|
|
|
2017-04-12 02:38:00 +02:00
|
|
|
static void Profile(FoldingSetNodeID &ID, ArrayRef<Attribute> AttrList) {
|
|
|
|
for (const auto &Attr : AttrList)
|
|
|
|
Attr.Profile(ID);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-24 01:06:56 +01:00
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
/// \class
|
2018-05-01 17:54:18 +02:00
|
|
|
/// This class represents a set of attributes that apply to the function,
|
2013-01-24 01:06:56 +01:00
|
|
|
/// 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
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
class AttributeListImpl final
|
2015-08-06 00:57:34 +02: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
llvm-svn: 303654
2017-05-23 19:01:48 +02: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
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
friend class AttributeList;
|
2015-08-06 00:57:34 +02:00
|
|
|
friend TrailingObjects;
|
2015-06-17 03:21:20 +02:00
|
|
|
|
|
|
|
private:
|
[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
|
|
|
unsigned NumAttrSets; ///< Number of entries in this set.
|
2020-06-14 23:46:18 +02:00
|
|
|
/// Available enum function attributes.
|
|
|
|
AttributeBitSet AvailableFunctionAttrs;
|
2020-06-14 22:49:57 +02:00
|
|
|
/// Union of enum attributes available at any index.
|
|
|
|
AttributeBitSet AvailableSomewhereAttrs;
|
2013-07-11 14:13:16 +02:00
|
|
|
|
2015-08-06 00:57:34 +02: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
llvm-svn: 303654
2017-05-23 19:01:48 +02:00
|
|
|
size_t numTrailingObjects(OverloadToken<AttributeSet>) { return NumAttrSets; }
|
2013-01-24 02:01:34 +01:00
|
|
|
|
2012-11-20 06:09:20 +01:00
|
|
|
public:
|
2020-05-01 14:18:29 +02:00
|
|
|
AttributeListImpl(ArrayRef<AttributeSet> Sets);
|
2013-01-04 21:54:35 +01:00
|
|
|
|
2016-12-07 23:06:02 +01: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
llvm-svn: 298393
2017-03-21 17:57:19 +01:00
|
|
|
AttributeListImpl(const AttributeListImpl &) = delete;
|
|
|
|
AttributeListImpl &operator=(const AttributeListImpl &) = delete;
|
2016-12-07 23:06:02 +01:00
|
|
|
|
2018-05-01 17:54:18 +02:00
|
|
|
/// Return true if the AttributeSet or the FunctionIndex has an
|
2016-01-29 23:25:19 +01:00
|
|
|
/// enum attribute of the given kind.
|
|
|
|
bool hasFnAttribute(Attribute::AttrKind Kind) const {
|
2020-06-14 23:46:18 +02:00
|
|
|
return AvailableFunctionAttrs.hasAttribute(Kind);
|
2016-01-29 23:25:19 +01:00
|
|
|
}
|
|
|
|
|
2020-06-14 22:49:57 +02:00
|
|
|
/// Return true if the specified attribute is set for at least one
|
|
|
|
/// 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;
|
|
|
|
|
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 { return getTrailingObjects<AttributeSet>(); }
|
|
|
|
iterator end() const { return begin() + NumAttrSets; }
|
2013-01-28 01:21:34 +01:00
|
|
|
|
2017-04-11 02:16:00 +02: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
llvm-svn: 303654
2017-05-23 19:01:48 +02:00
|
|
|
static void Profile(FoldingSetNodeID &ID, ArrayRef<AttributeSet> Nodes);
|
2013-01-28 00:41:29 +01:00
|
|
|
|
2013-08-03 00:34:30 +02:00
|
|
|
void dump() const;
|
2012-11-20 06:09:20 +01:00
|
|
|
};
|
|
|
|
|
2020-05-01 14:12:17 +02:00
|
|
|
static_assert(std::is_trivially_destructible<AttributeListImpl>::value,
|
|
|
|
"AttributeListImpl should be trivially destructible");
|
|
|
|
|
2016-12-07 23:06:02 +01:00
|
|
|
} // end namespace llvm
|
2012-09-26 23:07:29 +02:00
|
|
|
|
2016-12-07 23:06:02 +01:00
|
|
|
#endif // LLVM_LIB_IR_ATTRIBUTEIMPL_H
|