Simplify Attribute constructor definitions.

PiperOrigin-RevId: 228926113
This commit is contained in:
River Riddle 2019-01-11 12:33:12 -08:00 committed by jpienaar
parent c35d6b4f2d
commit ba9a544615
2 changed files with 33 additions and 70 deletions

View File

@ -136,12 +136,10 @@ inline raw_ostream &operator<<(raw_ostream &os, Attribute attr) {
class BoolAttr : public Attribute {
public:
using Attribute::Attribute;
using ImplType = detail::BoolAttributeStorage;
using ValueType = bool;
BoolAttr() = default;
/* implicit */ BoolAttr(Attribute::ImplType *ptr);
static BoolAttr get(bool value, MLIRContext *context);
bool getValue() const;
@ -152,12 +150,10 @@ public:
class IntegerAttr : public Attribute {
public:
using Attribute::Attribute;
using ImplType = detail::IntegerAttributeStorage;
using ValueType = APInt;
IntegerAttr() = default;
/* implicit */ IntegerAttr(Attribute::ImplType *ptr);
static IntegerAttr get(Type type, int64_t value);
static IntegerAttr get(Type type, const APInt &value);
@ -171,14 +167,12 @@ public:
static bool kindof(Kind kind) { return kind == Kind::Integer; }
};
class FloatAttr final : public Attribute {
class FloatAttr : public Attribute {
public:
using Attribute::Attribute;
using ImplType = detail::FloatAttributeStorage;
using ValueType = APFloat;
FloatAttr() = default;
/* implicit */ FloatAttr(Attribute::ImplType *ptr);
static FloatAttr get(Type type, double value);
static FloatAttr get(Type type, const APFloat &value);
@ -196,12 +190,10 @@ public:
class StringAttr : public Attribute {
public:
using Attribute::Attribute;
using ImplType = detail::StringAttributeStorage;
using ValueType = StringRef;
StringAttr() = default;
/* implicit */ StringAttr(Attribute::ImplType *ptr);
static StringAttr get(StringRef bytes, MLIRContext *context);
StringRef getValue() const;
@ -214,12 +206,10 @@ public:
/// type homogenous given that attributes don't, in general, carry types.
class ArrayAttr : public Attribute {
public:
using Attribute::Attribute;
using ImplType = detail::ArrayAttributeStorage;
using ValueType = ArrayRef<Attribute>;
ArrayAttr() = default;
/* implicit */ ArrayAttr(Attribute::ImplType *ptr);
static ArrayAttr get(ArrayRef<Attribute> value, MLIRContext *context);
ArrayRef<Attribute> getValue() const;
@ -236,12 +226,10 @@ public:
class AffineMapAttr : public Attribute {
public:
using Attribute::Attribute;
using ImplType = detail::AffineMapAttributeStorage;
using ValueType = AffineMap;
AffineMapAttr() = default;
/* implicit */ AffineMapAttr(Attribute::ImplType *ptr);
static AffineMapAttr get(AffineMap value);
AffineMap getValue() const;
@ -252,12 +240,10 @@ public:
class IntegerSetAttr : public Attribute {
public:
using Attribute::Attribute;
using ImplType = detail::IntegerSetAttributeStorage;
using ValueType = IntegerSet;
IntegerSetAttr() = default;
/* implicit */ IntegerSetAttr(Attribute::ImplType *ptr);
static IntegerSetAttr get(IntegerSet value);
IntegerSet getValue() const;
@ -268,12 +254,10 @@ public:
class TypeAttr : public Attribute {
public:
using Attribute::Attribute;
using ImplType = detail::TypeAttributeStorage;
using ValueType = Type;
TypeAttr() = default;
/* implicit */ TypeAttr(Attribute::ImplType *ptr);
static TypeAttr get(Type type, MLIRContext *context);
Type getValue() const;
@ -291,12 +275,10 @@ public:
/// remain in MLIRContext.
class FunctionAttr : public Attribute {
public:
using Attribute::Attribute;
using ImplType = detail::FunctionAttributeStorage;
using ValueType = Function *;
FunctionAttr() = default;
/* implicit */ FunctionAttr(Attribute::ImplType *ptr);
static FunctionAttr get(const Function *value, MLIRContext *context);
Function *getValue() const;
@ -314,9 +296,8 @@ public:
/// A base attribute represents a reference to a vector or tensor constant.
class ElementsAttr : public Attribute {
public:
using Attribute::Attribute;
typedef detail::ElementsAttributeStorage ImplType;
ElementsAttr() = default;
/* implicit */ ElementsAttr(Attribute::ImplType *ptr);
VectorOrTensorType getType() const;
@ -331,12 +312,10 @@ public:
/// meaning all of the elements have the same value.
class SplatElementsAttr : public ElementsAttr {
public:
using ElementsAttr::ElementsAttr;
using ImplType = detail::SplatElementsAttributeStorage;
using ValueType = Attribute;
SplatElementsAttr() = default;
/* implicit */ SplatElementsAttr(Attribute::ImplType *ptr);
static SplatElementsAttr get(VectorOrTensorType type, Attribute elt);
Attribute getValue() const;
@ -350,11 +329,9 @@ public:
/// than 64.
class DenseElementsAttr : public ElementsAttr {
public:
using ElementsAttr::ElementsAttr;
using ImplType = detail::DenseElementsAttributeStorage;
DenseElementsAttr() = default;
/* implicit */ DenseElementsAttr(Attribute::ImplType *ptr);
/// It assumes the elements in the input array have been truncated to the bits
/// width specified by the element type (note all float type are 64 bits).
/// When the value is retrieved, the bits are read from the storage and extend
@ -391,11 +368,9 @@ public:
/// object.
class DenseIntElementsAttr : public DenseElementsAttr {
public:
using DenseElementsAttr::DenseElementsAttr;
using ImplType = detail::DenseIntElementsAttributeStorage;
DenseIntElementsAttr() = default;
/* implicit */ DenseIntElementsAttr(Attribute::ImplType *ptr);
// TODO: returns APInts instead of IntegerAttr.
void getValues(SmallVectorImpl<Attribute> &values) const;
@ -409,11 +384,9 @@ public:
/// object. Each element is stored as a double.
class DenseFPElementsAttr : public DenseElementsAttr {
public:
using DenseElementsAttr::DenseElementsAttr;
using ImplType = detail::DenseFPElementsAttributeStorage;
DenseFPElementsAttr() = default;
/* implicit */ DenseFPElementsAttr(Attribute::ImplType *ptr);
// TODO: returns APFPs instead of FloatAttr.
void getValues(SmallVectorImpl<Attribute> &values) const;
@ -428,12 +401,10 @@ public:
/// doesn't need to interpret.
class OpaqueElementsAttr : public ElementsAttr {
public:
using ElementsAttr::ElementsAttr;
using ImplType = detail::OpaqueElementsAttributeStorage;
using ValueType = StringRef;
OpaqueElementsAttr() = default;
/* implicit */ OpaqueElementsAttr(Attribute::ImplType *ptr);
static OpaqueElementsAttr get(VectorOrTensorType type, StringRef bytes);
StringRef getValue() const;
@ -459,11 +430,9 @@ public:
/// [0, 0, 0, 0]].
class SparseElementsAttr : public ElementsAttr {
public:
using ElementsAttr::ElementsAttr;
using ImplType = detail::SparseElementsAttributeStorage;
SparseElementsAttr() = default;
/* implicit */ SparseElementsAttr(Attribute::ImplType *ptr);
static SparseElementsAttr get(VectorOrTensorType type,
DenseIntElementsAttr indices,
DenseElementsAttr values);

View File

@ -64,11 +64,11 @@ Attribute Attribute::remapFunctionAttrs(
return ArrayAttr::get(remappedElts, context);
}
BoolAttr::BoolAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// BoolAttr
bool BoolAttr::getValue() const { return static_cast<ImplType *>(attr)->value; }
IntegerAttr::IntegerAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// IntegerAttr
APInt IntegerAttr::getValue() const {
return static_cast<ImplType *>(attr)->getValue();
@ -80,7 +80,7 @@ Type IntegerAttr::getType() const {
return static_cast<ImplType *>(attr)->type;
}
FloatAttr::FloatAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// FloatAttr
APFloat FloatAttr::getValue() const {
return static_cast<ImplType *>(attr)->getValue();
@ -99,35 +99,35 @@ double FloatAttr::getValueAsDouble() const {
return value.convertToDouble();
}
StringAttr::StringAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// StringAttr
StringRef StringAttr::getValue() const {
return static_cast<ImplType *>(attr)->value;
}
ArrayAttr::ArrayAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// ArrayAttr
ArrayRef<Attribute> ArrayAttr::getValue() const {
return static_cast<ImplType *>(attr)->value;
}
AffineMapAttr::AffineMapAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// AffineMapAttr
AffineMap AffineMapAttr::getValue() const {
return static_cast<ImplType *>(attr)->value;
}
IntegerSetAttr::IntegerSetAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// IntegerSetAttr
IntegerSet IntegerSetAttr::getValue() const {
return static_cast<ImplType *>(attr)->value;
}
TypeAttr::TypeAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// TypeAttr
Type TypeAttr::getValue() const { return static_cast<ImplType *>(attr)->value; }
FunctionAttr::FunctionAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// FunctionAttr
Function *FunctionAttr::getValue() const {
return static_cast<ImplType *>(attr)->value;
@ -135,21 +135,19 @@ Function *FunctionAttr::getValue() const {
FunctionType FunctionAttr::getType() const { return getValue()->getType(); }
ElementsAttr::ElementsAttr(Attribute::ImplType *ptr) : Attribute(ptr) {}
/// ElementsAttr
VectorOrTensorType ElementsAttr::getType() const {
return static_cast<ImplType *>(attr)->type;
}
SplatElementsAttr::SplatElementsAttr(Attribute::ImplType *ptr)
: ElementsAttr(ptr) {}
/// SplatElementsAttr
Attribute SplatElementsAttr::getValue() const {
return static_cast<ImplType *>(attr)->elt;
}
DenseElementsAttr::DenseElementsAttr(Attribute::ImplType *ptr)
: ElementsAttr(ptr) {}
/// DenseElementsAttr
void DenseElementsAttr::getValues(SmallVectorImpl<Attribute> &values) const {
switch (getKind()) {
@ -209,8 +207,7 @@ uint64_t DenseElementsAttr::readBits(const char *rawData, size_t bitPos,
return dst;
}
DenseIntElementsAttr::DenseIntElementsAttr(Attribute::ImplType *ptr)
: DenseElementsAttr(ptr) {}
/// DenseIntElementsAttr
void DenseIntElementsAttr::getValues(SmallVectorImpl<Attribute> &values) const {
auto bitsWidth = static_cast<ImplType *>(attr)->bitsWidth;
@ -236,8 +233,7 @@ void DenseIntElementsAttr::getValues(SmallVectorImpl<Attribute> &values) const {
}
}
DenseFPElementsAttr::DenseFPElementsAttr(Attribute::ImplType *ptr)
: DenseElementsAttr(ptr) {}
/// DenseFPElementsAttr
// Construct a FloatAttr wrapping a float value of `elementType` type from its
// bit representation. The APFloat stored in the attribute will have the
@ -274,15 +270,13 @@ void DenseFPElementsAttr::getValues(SmallVectorImpl<Attribute> &values) const {
}
}
OpaqueElementsAttr::OpaqueElementsAttr(Attribute::ImplType *ptr)
: ElementsAttr(ptr) {}
/// OpaqueElementsAttr
StringRef OpaqueElementsAttr::getValue() const {
return static_cast<ImplType *>(attr)->bytes;
}
SparseElementsAttr::SparseElementsAttr(Attribute::ImplType *ptr)
: ElementsAttr(ptr) {}
/// SparseElementsAttr
DenseIntElementsAttr SparseElementsAttr::getIndices() const {
return static_cast<ImplType *>(attr)->indices;