NFC: Add wrappers around DenseIntElementsAttr/DenseFPElementsAttr::get 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
This commit is contained in:
River Riddle 2019-11-21 09:57:43 -08:00 committed by A. Unique TensorFlower
parent 0abec2744c
commit c621e64150
1 changed files with 28 additions and 0 deletions

View File

@ -974,6 +974,20 @@ public:
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
@ -998,6 +1012,20 @@ public:
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