aboutsummaryrefslogtreecommitdiff
path: root/lib/IR/AttributeImpl.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/IR/AttributeImpl.h')
-rw-r--r--lib/IR/AttributeImpl.h51
1 files changed, 38 insertions, 13 deletions
diff --git a/lib/IR/AttributeImpl.h b/lib/IR/AttributeImpl.h
index bb0c072e4781..f989fa3b910e 100644
--- a/lib/IR/AttributeImpl.h
+++ b/lib/IR/AttributeImpl.h
@@ -1,9 +1,8 @@
//===- AttributeImpl.h - Attribute Internals --------------------*- C++ -*-===//
//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
+// 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
//
//===----------------------------------------------------------------------===//
///
@@ -30,6 +29,7 @@
namespace llvm {
class LLVMContext;
+class Type;
//===----------------------------------------------------------------------===//
/// \class
@@ -42,7 +42,8 @@ protected:
enum AttrEntryKind {
EnumAttrEntry,
IntAttrEntry,
- StringAttrEntry
+ StringAttrEntry,
+ TypeAttrEntry,
};
AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {}
@@ -57,6 +58,7 @@ public:
bool isEnumAttribute() const { return KindID == EnumAttrEntry; }
bool isIntAttribute() const { return KindID == IntAttrEntry; }
bool isStringAttribute() const { return KindID == StringAttrEntry; }
+ bool isTypeAttribute() const { return KindID == TypeAttrEntry; }
bool hasAttribute(Attribute::AttrKind A) const;
bool hasAttribute(StringRef Kind) const;
@@ -67,16 +69,20 @@ public:
StringRef getKindAsString() const;
StringRef getValueAsString() const;
+ Type *getValueAsType() const;
+
/// Used when sorting the attributes.
bool operator<(const AttributeImpl &AI) const;
void Profile(FoldingSetNodeID &ID) const {
if (isEnumAttribute())
- Profile(ID, getKindAsEnum(), 0);
+ Profile(ID, getKindAsEnum(), static_cast<uint64_t>(0));
else if (isIntAttribute())
Profile(ID, getKindAsEnum(), getValueAsInt());
- else
+ else if (isStringAttribute())
Profile(ID, getKindAsString(), getValueAsString());
+ else
+ Profile(ID, getKindAsEnum(), getValueAsType());
}
static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
@@ -89,6 +95,12 @@ public:
ID.AddString(Kind);
if (!Values.empty()) ID.AddString(Values);
}
+
+ static void Profile(FoldingSetNodeID &ID, Attribute::AttrKind Kind,
+ Type *Ty) {
+ ID.AddInteger(Kind);
+ ID.AddPointer(Ty);
+ }
};
//===----------------------------------------------------------------------===//
@@ -146,6 +158,18 @@ public:
StringRef getStringValue() const { return Val; }
};
+class TypeAttributeImpl : public EnumAttributeImpl {
+ virtual void anchor();
+
+ Type *Ty;
+
+public:
+ TypeAttributeImpl(Attribute::AttrKind Kind, Type *Ty)
+ : EnumAttributeImpl(TypeAttrEntry, Kind), Ty(Ty) {}
+
+ Type *getTypeValue() const { return Ty; }
+};
+
//===----------------------------------------------------------------------===//
/// \class
/// This class represents a group of attributes that apply to one
@@ -155,9 +179,9 @@ class AttributeSetNode final
private TrailingObjects<AttributeSetNode, Attribute> {
friend TrailingObjects;
- /// Bitset with a bit for each available attribute Attribute::AttrKind.
- uint64_t AvailableAttrs;
unsigned NumAttrs; ///< Number of attributes in this node.
+ /// Bitset with a bit for each available attribute Attribute::AttrKind.
+ uint8_t AvailableAttrs[12] = {};
AttributeSetNode(ArrayRef<Attribute> Attrs);
@@ -176,7 +200,7 @@ public:
unsigned getNumAttributes() const { return NumAttrs; }
bool hasAttribute(Attribute::AttrKind Kind) const {
- return AvailableAttrs & ((uint64_t)1) << Kind;
+ return AvailableAttrs[Kind / 8] & ((uint64_t)1) << (Kind % 8);
}
bool hasAttribute(StringRef Kind) const;
bool hasAttributes() const { return NumAttrs != 0; }
@@ -190,6 +214,7 @@ public:
uint64_t getDereferenceableOrNullBytes() const;
std::pair<unsigned, Optional<unsigned>> getAllocSizeArgs() const;
std::string getAsString(bool InAttrGrp) const;
+ Type *getByValType() const;
using iterator = const Attribute *;
@@ -219,10 +244,10 @@ class AttributeListImpl final
friend TrailingObjects;
private:
- /// Bitset with a bit for each available attribute Attribute::AttrKind.
- uint64_t AvailableFunctionAttrs;
LLVMContext &Context;
unsigned NumAttrSets; ///< Number of entries in this set.
+ /// Bitset with a bit for each available attribute Attribute::AttrKind.
+ uint8_t AvailableFunctionAttrs[12] = {};
// Helper fn for TrailingObjects class.
size_t numTrailingObjects(OverloadToken<AttributeSet>) { return NumAttrSets; }
@@ -242,7 +267,7 @@ public:
/// Return true if the AttributeSet or the FunctionIndex has an
/// enum attribute of the given kind.
bool hasFnAttribute(Attribute::AttrKind Kind) const {
- return AvailableFunctionAttrs & ((uint64_t)1) << Kind;
+ return AvailableFunctionAttrs[Kind / 8] & ((uint64_t)1) << (Kind % 8);
}
using iterator = const AttributeSet *;