summaryrefslogtreecommitdiffstats
path: root/llvm/lib/IR/AttributeImpl.h
diff options
context:
space:
mode:
authorTim Northover <tnorthover@apple.com>2019-05-30 18:48:23 +0000
committerTim Northover <tnorthover@apple.com>2019-05-30 18:48:23 +0000
commitb7141207a483d39b99c2b4da4eb3bb591eca9e1a (patch)
tree17be3c9e9f0ba7f9493e2279d5df0e029533d910 /llvm/lib/IR/AttributeImpl.h
parent7fecdf36cc5b41dc5ad85d58c6e3b97b4fce6d00 (diff)
downloadbcm5719-llvm-b7141207a483d39b99c2b4da4eb3bb591eca9e1a.tar.gz
bcm5719-llvm-b7141207a483d39b99c2b4da4eb3bb591eca9e1a.zip
Reapply: IR: add optional type to 'byval' function parameters
When we switch to opaque pointer types we will need some way to describe how many bytes a 'byval' parameter should occupy on the stack. This adds a (for now) optional extra type parameter. If present, the type must match the pointee type of the argument. The original commit did not remap byval types when linking modules, which broke LTO. This version fixes that. Note to front-end maintainers: if this causes test failures, it's probably because the "byval" attribute is printed after attributes without any parameter after this change. llvm-svn: 362128
Diffstat (limited to 'llvm/lib/IR/AttributeImpl.h')
-rw-r--r--llvm/lib/IR/AttributeImpl.h32
1 files changed, 29 insertions, 3 deletions
diff --git a/llvm/lib/IR/AttributeImpl.h b/llvm/lib/IR/AttributeImpl.h
index 8ebcb04a565..f6898476382 100644
--- a/llvm/lib/IR/AttributeImpl.h
+++ b/llvm/lib/IR/AttributeImpl.h
@@ -29,6 +29,7 @@
namespace llvm {
class LLVMContext;
+class Type;
//===----------------------------------------------------------------------===//
/// \class
@@ -41,7 +42,8 @@ protected:
enum AttrEntryKind {
EnumAttrEntry,
IntAttrEntry,
- StringAttrEntry
+ StringAttrEntry,
+ TypeAttrEntry,
};
AttributeImpl(AttrEntryKind KindID) : KindID(KindID) {}
@@ -56,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;
@@ -66,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,
@@ -88,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);
+ }
};
//===----------------------------------------------------------------------===//
@@ -145,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
@@ -189,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 *;
OpenPOWER on IntegriCloud