forked from OSchip/llvm-project
Add an overloaded 'get' method to DenseElementsAttr that accepts an initializer_list.
PiperOrigin-RevId: 253234385
This commit is contained in:
parent
b582338f62
commit
5624bc289e
|
@ -512,6 +512,15 @@ public:
|
|||
/// shape.
|
||||
static DenseElementsAttr get(ShapedType type, ArrayRef<APFloat> values);
|
||||
|
||||
/// Construct a dense elements attribute for an initializer_list of values.
|
||||
/// Each value is expected to be the same bitwidth of the element type of
|
||||
/// 'type'. 'type' must be a vector or tensor with static shape.
|
||||
template <typename T>
|
||||
static DenseElementsAttr get(const ShapedType &type,
|
||||
const std::initializer_list<T> &list) {
|
||||
return get(type, ArrayRef<T>(list));
|
||||
}
|
||||
|
||||
//===--------------------------------------------------------------------===//
|
||||
// Iterators
|
||||
//===--------------------------------------------------------------------===//
|
||||
|
|
|
@ -43,23 +43,19 @@ TEST(DenseSplatTest, BoolSplat) {
|
|||
|
||||
// Check that splat is automatically detected for boolean values.
|
||||
/// True.
|
||||
DenseElementsAttr trueSplat =
|
||||
DenseElementsAttr::get(shape, llvm::ArrayRef<bool>(true));
|
||||
DenseElementsAttr trueSplat = DenseElementsAttr::get(shape, true);
|
||||
EXPECT_TRUE(trueSplat.isSplat());
|
||||
/// False.
|
||||
DenseElementsAttr falseSplat =
|
||||
DenseElementsAttr::get(shape, llvm::ArrayRef<bool>(false));
|
||||
DenseElementsAttr falseSplat = DenseElementsAttr::get(shape, false);
|
||||
EXPECT_TRUE(falseSplat.isSplat());
|
||||
EXPECT_NE(falseSplat, trueSplat);
|
||||
|
||||
/// Detect and handle splat within 8 elements (bool values are bit-packed).
|
||||
/// True.
|
||||
auto detectedSplat = DenseElementsAttr::get(
|
||||
shape, llvm::ArrayRef<bool>({true, true, true, true}));
|
||||
auto detectedSplat = DenseElementsAttr::get(shape, {true, true, true, true});
|
||||
EXPECT_EQ(detectedSplat, trueSplat);
|
||||
/// False.
|
||||
detectedSplat = DenseElementsAttr::get(
|
||||
shape, llvm::ArrayRef<bool>({false, false, false, false}));
|
||||
detectedSplat = DenseElementsAttr::get(shape, {false, false, false, false});
|
||||
EXPECT_EQ(detectedSplat, falseSplat);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue