Skip to content

Commit

Permalink
[mlir] Remove the use of "kinds" from Attributes and Types
Browse files Browse the repository at this point in the history
This greatly simplifies a large portion of the underlying infrastructure, allows for lookups of singleton classes to be much more efficient and always thread-safe(no locking). As a result of this, the dialect symbol registry has been removed as it is no longer necessary.

For users broken by this change, an alert was sent out(https://llvm.discourse.group/t/removing-kinds-from-attributes-and-types) that helps prevent a majority of the breakage surface area. All that should be necessary, if the advice in that alert was followed, is removing the kind passed to the ::get methods.

Differential Revision: https://reviews.llvm.org/D86121
  • Loading branch information
River707 committed Aug 18, 2020
1 parent a7d0b7a commit 250f43d
Show file tree
Hide file tree
Showing 42 changed files with 593 additions and 894 deletions.
27 changes: 0 additions & 27 deletions flang/include/flang/Optimizer/Dialect/FIRAttr.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,6 @@ struct RealAttributeStorage;
struct TypeAttributeStorage;
} // namespace detail

enum AttributeKind {
FIR_ATTR = mlir::Attribute::FIRST_FIR_ATTR,
FIR_EXACTTYPE, // instance_of, precise type relation
FIR_SUBCLASS, // subsumed_by, is-a (subclass) relation
FIR_POINT,
FIR_CLOSEDCLOSED_INTERVAL,
FIR_OPENCLOSED_INTERVAL,
FIR_CLOSEDOPEN_INTERVAL,
FIR_REAL_ATTR,
};

class ExactTypeAttr
: public mlir::Attribute::AttrBase<ExactTypeAttr, mlir::Attribute,
detail::TypeAttributeStorage> {
Expand All @@ -47,8 +36,6 @@ class ExactTypeAttr
static ExactTypeAttr get(mlir::Type value);

mlir::Type getType() const;

static constexpr unsigned getId() { return AttributeKind::FIR_EXACTTYPE; }
};

class SubclassAttr
Expand All @@ -62,8 +49,6 @@ class SubclassAttr
static SubclassAttr get(mlir::Type value);

mlir::Type getType() const;

static constexpr unsigned getId() { return AttributeKind::FIR_SUBCLASS; }
};

// Attributes for building SELECT CASE multiway branches
Expand All @@ -80,9 +65,6 @@ class ClosedIntervalAttr

static constexpr llvm::StringRef getAttrName() { return "interval"; }
static ClosedIntervalAttr get(mlir::MLIRContext *ctxt);
static constexpr unsigned getId() {
return AttributeKind::FIR_CLOSEDCLOSED_INTERVAL;
}
};

/// An upper bound is an open interval (including the bound value) as given as
Expand All @@ -97,9 +79,6 @@ class UpperBoundAttr

static constexpr llvm::StringRef getAttrName() { return "upper"; }
static UpperBoundAttr get(mlir::MLIRContext *ctxt);
static constexpr unsigned getId() {
return AttributeKind::FIR_OPENCLOSED_INTERVAL;
}
};

/// A lower bound is an open interval (including the bound value) as given as
Expand All @@ -114,9 +93,6 @@ class LowerBoundAttr

static constexpr llvm::StringRef getAttrName() { return "lower"; }
static LowerBoundAttr get(mlir::MLIRContext *ctxt);
static constexpr unsigned getId() {
return AttributeKind::FIR_CLOSEDOPEN_INTERVAL;
}
};

/// A pointer interval is a closed interval as given as an ssa-value. The
Expand All @@ -131,7 +107,6 @@ class PointIntervalAttr

static constexpr llvm::StringRef getAttrName() { return "point"; }
static PointIntervalAttr get(mlir::MLIRContext *ctxt);
static constexpr unsigned getId() { return AttributeKind::FIR_POINT; }
};

/// A real attribute is used to workaround MLIR's default parsing of a real
Expand All @@ -150,8 +125,6 @@ class RealAttr

int getFKind() const;
llvm::APFloat getValue() const;

static constexpr unsigned getId() { return AttributeKind::FIR_REAL_ATTR; }
};

mlir::Attribute parseFirAttribute(FIROpsDialect *dialect,
Expand Down
45 changes: 5 additions & 40 deletions flang/include/flang/Optimizer/Dialect/FIRType.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,29 +54,6 @@ struct SequenceTypeStorage;
struct TypeDescTypeStorage;
} // namespace detail

/// Integral identifier for all the types comprising the FIR type system
enum TypeKind {
// The enum starts at the range reserved for this dialect.
FIR_TYPE = mlir::Type::FIRST_FIR_TYPE,
FIR_BOX, // (static) descriptor
FIR_BOXCHAR, // CHARACTER pointer and length
FIR_BOXPROC, // procedure with host association
FIR_CHARACTER, // intrinsic type
FIR_COMPLEX, // intrinsic type
FIR_DERIVED, // derived
FIR_DIMS,
FIR_FIELD,
FIR_HEAP,
FIR_INT, // intrinsic type
FIR_LEN,
FIR_LOGICAL, // intrinsic type
FIR_POINTER, // POINTER attr
FIR_REAL, // intrinsic type
FIR_REFERENCE,
FIR_SEQUENCE, // DIMENSION attr
FIR_TYPEDESC,
};

// These isa_ routines follow the precedent of llvm::isa_or_null<>

/// Is `t` any of the FIR dialect types?
Expand Down Expand Up @@ -111,21 +88,14 @@ bool isa_aggregate(mlir::Type t);
/// not a memory reference type, then returns a null `Type`.
mlir::Type dyn_cast_ptrEleTy(mlir::Type t);

/// Boilerplate mixin template
template <typename A, unsigned Id>
struct IntrinsicTypeMixin {
static constexpr unsigned getId() { return Id; }
};

// Intrinsic types

/// Model of the Fortran CHARACTER intrinsic type, including the KIND type
/// parameter. The model does not include a LEN type parameter. A CharacterType
/// is thus the type of a single character value.
class CharacterType
: public mlir::Type::TypeBase<CharacterType, mlir::Type,
detail::CharacterTypeStorage>,
public IntrinsicTypeMixin<CharacterType, TypeKind::FIR_CHARACTER> {
detail::CharacterTypeStorage> {
public:
using Base::Base;
static CharacterType get(mlir::MLIRContext *ctxt, KindTy kind);
Expand All @@ -136,8 +106,7 @@ class CharacterType
/// parameter. COMPLEX is a floating point type with a real and imaginary
/// member.
class CplxType : public mlir::Type::TypeBase<CplxType, mlir::Type,
detail::CplxTypeStorage>,
public IntrinsicTypeMixin<CplxType, TypeKind::FIR_COMPLEX> {
detail::CplxTypeStorage> {
public:
using Base::Base;
static CplxType get(mlir::MLIRContext *ctxt, KindTy kind);
Expand All @@ -151,8 +120,7 @@ class CplxType : public mlir::Type::TypeBase<CplxType, mlir::Type,
/// Model of a Fortran INTEGER intrinsic type, including the KIND type
/// parameter.
class IntType
: public mlir::Type::TypeBase<IntType, mlir::Type, detail::IntTypeStorage>,
public IntrinsicTypeMixin<IntType, TypeKind::FIR_INT> {
: public mlir::Type::TypeBase<IntType, mlir::Type, detail::IntTypeStorage> {
public:
using Base::Base;
static IntType get(mlir::MLIRContext *ctxt, KindTy kind);
Expand All @@ -163,8 +131,7 @@ class IntType
/// parameter.
class LogicalType
: public mlir::Type::TypeBase<LogicalType, mlir::Type,
detail::LogicalTypeStorage>,
public IntrinsicTypeMixin<LogicalType, TypeKind::FIR_LOGICAL> {
detail::LogicalTypeStorage> {
public:
using Base::Base;
static LogicalType get(mlir::MLIRContext *ctxt, KindTy kind);
Expand All @@ -174,8 +141,7 @@ class LogicalType
/// Model of a Fortran REAL (and DOUBLE PRECISION) intrinsic type, including the
/// KIND type parameter.
class RealType : public mlir::Type::TypeBase<RealType, mlir::Type,
detail::RealTypeStorage>,
public IntrinsicTypeMixin<RealType, TypeKind::FIR_REAL> {
detail::RealTypeStorage> {
public:
using Base::Base;
static RealType get(mlir::MLIRContext *ctxt, KindTy kind);
Expand Down Expand Up @@ -400,7 +366,6 @@ class RecordType : public mlir::Type::TypeBase<RecordType, mlir::Type,
static RecordType get(mlir::MLIRContext *ctxt, llvm::StringRef name);
void finalize(llvm::ArrayRef<TypePair> lenPList,
llvm::ArrayRef<TypePair> typeList);
static constexpr unsigned getId() { return TypeKind::FIR_DERIVED; }

detail::RecordTypeStorage const *uniqueKey() const;

Expand Down
14 changes: 7 additions & 7 deletions flang/lib/Optimizer/Dialect/FIRAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,40 +74,40 @@ struct TypeAttributeStorage : public mlir::AttributeStorage {
} // namespace detail

ExactTypeAttr ExactTypeAttr::get(mlir::Type value) {
return Base::get(value.getContext(), FIR_EXACTTYPE, value);
return Base::get(value.getContext(), value);
}

mlir::Type ExactTypeAttr::getType() const { return getImpl()->getType(); }

SubclassAttr SubclassAttr::get(mlir::Type value) {
return Base::get(value.getContext(), FIR_SUBCLASS, value);
return Base::get(value.getContext(), value);
}

mlir::Type SubclassAttr::getType() const { return getImpl()->getType(); }

using AttributeUniquer = mlir::detail::AttributeUniquer;

ClosedIntervalAttr ClosedIntervalAttr::get(mlir::MLIRContext *ctxt) {
return AttributeUniquer::get<ClosedIntervalAttr>(ctxt, getId());
return AttributeUniquer::get<ClosedIntervalAttr>(ctxt);
}

UpperBoundAttr UpperBoundAttr::get(mlir::MLIRContext *ctxt) {
return AttributeUniquer::get<UpperBoundAttr>(ctxt, getId());
return AttributeUniquer::get<UpperBoundAttr>(ctxt);
}

LowerBoundAttr LowerBoundAttr::get(mlir::MLIRContext *ctxt) {
return AttributeUniquer::get<LowerBoundAttr>(ctxt, getId());
return AttributeUniquer::get<LowerBoundAttr>(ctxt);
}

PointIntervalAttr PointIntervalAttr::get(mlir::MLIRContext *ctxt) {
return AttributeUniquer::get<PointIntervalAttr>(ctxt, getId());
return AttributeUniquer::get<PointIntervalAttr>(ctxt);
}

// RealAttr

RealAttr RealAttr::get(mlir::MLIRContext *ctxt,
const RealAttr::ValueType &key) {
return Base::get(ctxt, getId(), key);
return Base::get(ctxt, key);
}

int RealAttr::getFKind() const { return getImpl()->getFKind(); }
Expand Down
Loading

0 comments on commit 250f43d

Please sign in to comment.