Skip to content

Commit

Permalink
NFC: Add wrappers around DenseIntElementsAttr/DenseFPElementsAttr::ge…
Browse files Browse the repository at this point in the history
…t to avoid the need to cast.

This avoids the need to cast back to the derived type when calling get, i.e. removes the need to do DenseIntElementsAttr::get(...).cast<DenseIntElementsAttr>().

PiperOrigin-RevId: 281772163
  • Loading branch information
River707 authored and tensorflower-gardener committed Nov 21, 2019
1 parent 0abec27 commit c621e64
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions mlir/include/mlir/IR/Attributes.h
Expand Up @@ -974,6 +974,20 @@ class DenseFPElementsAttr : public DenseElementsAttr {

using DenseElementsAttr::DenseElementsAttr;

/// Get an instance of a DenseFPElementsAttr with the given arguments. This
/// simply wraps the DenseElementsAttr::get calls.
template <typename Arg>
static DenseFPElementsAttr get(const ShapedType &type, Arg &&arg) {
return DenseElementsAttr::get(type, llvm::makeArrayRef(arg))
.template cast<DenseFPElementsAttr>();
}
template <typename T>
static DenseFPElementsAttr get(const ShapedType &type,
const std::initializer_list<T> &list) {
return DenseElementsAttr::get(type, list)
.template cast<DenseFPElementsAttr>();
}

/// Generates a new DenseElementsAttr by mapping each value attribute, and
/// constructing the DenseElementsAttr given the new element type.
DenseElementsAttr
Expand All @@ -998,6 +1012,20 @@ class DenseIntElementsAttr : public DenseElementsAttr {

using DenseElementsAttr::DenseElementsAttr;

/// Get an instance of a DenseIntElementsAttr with the given arguments. This
/// simply wraps the DenseElementsAttr::get calls.
template <typename Arg>
static DenseIntElementsAttr get(const ShapedType &type, Arg &&arg) {
return DenseElementsAttr::get(type, llvm::makeArrayRef(arg))
.template cast<DenseIntElementsAttr>();
}
template <typename T>
static DenseIntElementsAttr get(const ShapedType &type,
const std::initializer_list<T> &list) {
return DenseElementsAttr::get(type, list)
.template cast<DenseIntElementsAttr>();
}

/// Generates a new DenseElementsAttr by mapping each value attribute, and
/// constructing the DenseElementsAttr given the new element type.
DenseElementsAttr
Expand Down

0 comments on commit c621e64

Please sign in to comment.