2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -915,7 +915,7 @@ def LLVM_SwitchOp : LLVM_TerminatorOp<"switch",
Variadic<AnyType>:$defaultOperands,
VariadicOfVariadic<AnyType, "case_operand_segments">:$caseOperands,
OptionalAttr<ElementsAttr>:$case_values,
ElementsAttr:$case_operand_segments,
DenseI32ArrayAttr:$case_operand_segments,
OptionalAttr<ElementsAttr>:$branch_weights
);
let successors = (successor
Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class AllocLikeOp<string mnemonic,
$_state.addOperands(dynamicSizes);
$_state.addOperands(symbolOperands);
$_state.addAttribute(getOperandSegmentSizeAttr(),
$_builder.getI32VectorAttr({
$_builder.getDenseI32ArrayAttr({
static_cast<int32_t>(dynamicSizes.size()),
static_cast<int32_t>(symbolOperands.size())}));
if (alignment)
Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ def PDLInterp_CreateOperationOp
```mlir
// Create an instance of a `foo.op` operation.
%op = pdl_interp.create_operation "foo.op"(%arg0 : !pdl.value) {"attrA" = %attr0} -> (%type : !pdl.type)

// Create an instance of a `foo.op` operation that has inferred result types
// (using the InferTypeOpInterface).
%op = pdl_interp.create_operation "foo.op"(%arg0 : !pdl.value) {"attrA" = %attr0} -> <inferred>
Expand Down
6 changes: 3 additions & 3 deletions mlir/include/mlir/IR/BuiltinAttributes.td
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ def Builtin_DenseArrayBase : Builtin_Attr<
Examples:

```mlir
[:i8]
[:i32 10, 42]
[:f64 42., 12.]
array<i8:>
array<i32: 10, 42>
array<f64: 42., 12.>
```

when a specific subclass is used as argument of an operation, the declarative
Expand Down
8 changes: 4 additions & 4 deletions mlir/include/mlir/IR/ValueRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#ifndef MLIR_IR_VALUERANGE_H
#define MLIR_IR_VALUERANGE_H

#include "mlir/IR/BuiltinAttributes.h"
#include "mlir/IR/Types.h"
#include "mlir/IR/Value.h"
#include "llvm/ADT/PointerUnion.h"
Expand All @@ -22,7 +23,6 @@ namespace mlir {
class ValueRange;
template <typename ValueRangeT>
class ValueTypeRange;
class ElementsAttr;
class TypeRangeRange;
template <typename ValueIteratorT>
class ValueTypeIterator;
Expand Down Expand Up @@ -54,7 +54,7 @@ class OperandRange final : public llvm::detail::indexed_accessor_range_base<

/// Split this range into a set of contiguous subranges using the given
/// elements attribute, which contains the sizes of the sub ranges.
OperandRangeRange split(ElementsAttr segmentSizes) const;
OperandRangeRange split(DenseI32ArrayAttr segmentSizes) const;

private:
/// See `llvm::detail::indexed_accessor_range_base` for details.
Expand Down Expand Up @@ -114,8 +114,8 @@ class OperandRangeRange final
class MutableOperandRange {
public:
/// A pair of a named attribute corresponding to an operand segment attribute,
/// and the index within that attribute. The attribute should correspond to an
/// i32 DenseElementsAttr.
/// and the index within that attribute. The attribute should correspond to a
/// dense i32 array attr.
using OperandSegment = std::pair<unsigned, NamedAttribute>;

/// Construct a new mutable range from the given operand, operand start index,
Expand Down
24 changes: 14 additions & 10 deletions mlir/lib/AsmParser/AttributeParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,6 @@ Attribute Parser::parseAttribute(Type type) {
// Parse an array attribute.
case Token::l_square: {
consumeToken(Token::l_square);
if (consumeIf(Token::colon))
return parseDenseArrayAttr();
SmallVector<Attribute, 4> elements;
auto parseElt = [&]() -> ParseResult {
elements.push_back(parseAttribute());
Expand Down Expand Up @@ -100,6 +98,10 @@ Attribute Parser::parseAttribute(Type type) {
case Token::kw_dense_resource:
return parseDenseResourceElementsAttr(type);

// Parse a dense array attribute.
case Token::kw_array:
return parseDenseArrayAttr(type);

// Parse a dictionary attribute.
case Token::l_brace: {
NamedAttrList elements;
Expand Down Expand Up @@ -833,15 +835,19 @@ class CustomAsmParser : public AsmParserImpl<AsmParser> {
} // namespace

/// Parse a dense array attribute.
Attribute Parser::parseDenseArrayAttr() {
auto typeLoc = getToken().getLoc();
auto type = parseType();
if (!type)
Attribute Parser::parseDenseArrayAttr(Type type) {
consumeToken(Token::kw_array);
SMLoc typeLoc = getToken().getLoc();
if (parseToken(Token::less, "expected '<' after 'array'"))
return {};
if (!type &&
(!(type = parseType()) ||
parseToken(Token::colon, "expected ':' after dense array type")))
return {};
CustomAsmParser parser(*this);
Attribute result;
// Check for empty list.
bool isEmptyList = getToken().is(Token::r_square);
bool isEmptyList = getToken().is(Token::greater);

if (auto intType = type.dyn_cast<IntegerType>()) {
switch (type.getIntOrFloatBitWidth()) {
Expand Down Expand Up @@ -901,10 +907,8 @@ Attribute Parser::parseDenseArrayAttr() {
emitError(typeLoc, "expected integer or float type, got: ") << type;
return {};
}
if (!consumeIf(Token::r_square)) {
emitError("expected ']' to close an array attribute");
if (parseToken(Token::greater, "expected '>' to close an array attribute"))
return {};
}
return result;
}

Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/AsmParser/Parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ class Parser {
Attribute parseDenseResourceElementsAttr(Type attrType);

/// Parse a DenseArrayAttr.
Attribute parseDenseArrayAttr();
Attribute parseDenseArrayAttr(Type type);

/// Parse a sparse elements attribute.
Attribute parseSparseElementsAttr(Type attrType);
Expand Down
1 change: 1 addition & 0 deletions mlir/lib/AsmParser/TokenKinds.def
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ TOK_PUNCTUATION(file_metadata_end, "#-}")
// this list and to cater to OCD.
TOK_KEYWORD(affine_map)
TOK_KEYWORD(affine_set)
TOK_KEYWORD(array)
TOK_KEYWORD(attributes)
TOK_KEYWORD(bf16)
TOK_KEYWORD(ceildiv)
Expand Down
10 changes: 4 additions & 6 deletions mlir/lib/Dialect/Async/IR/Async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,8 @@ void ExecuteOp::build(OpBuilder &builder, OperationState &result,
// Add derived `operand_segment_sizes` attribute based on parsed operands.
int32_t numDependencies = dependencies.size();
int32_t numOperands = operands.size();
auto operandSegmentSizes = DenseIntElementsAttr::get(
VectorType::get({2}, builder.getIntegerType(32)),
{numDependencies, numOperands});
auto operandSegmentSizes =
builder.getDenseI32ArrayAttr({numDependencies, numOperands});
result.addAttribute(kOperandSegmentSizesAttr, operandSegmentSizes);

// First result is always a token, and then `resultTypes` wrapped into
Expand Down Expand Up @@ -203,9 +202,8 @@ ParseResult ExecuteOp::parse(OpAsmParser &parser, OperationState &result) {
int32_t numOperands = valueArgs.size();

// Add derived `operand_segment_sizes` attribute based on parsed operands.
auto operandSegmentSizes = DenseIntElementsAttr::get(
VectorType::get({2}, parser.getBuilder().getI32Type()),
{numDependencies, numOperands});
auto operandSegmentSizes =
parser.getBuilder().getDenseI32ArrayAttr({numDependencies, numOperands});
result.addAttribute(kOperandSegmentSizesAttr, operandSegmentSizes);

// Parse the types of results returned from the async execute op.
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ ParseResult AllocTensorOp::parse(OpAsmParser &parser, OperationState &result) {
if (parser.resolveOperand(copyOperand, type, result.operands))
return failure();
result.addAttribute(AllocTensorOp::getOperandSegmentSizeAttr(),
parser.getBuilder().getI32VectorAttr(
parser.getBuilder().getDenseI32ArrayAttr(
{static_cast<int32_t>(dynamicSizesOperands.size()),
static_cast<int32_t>(copyKeyword.succeeded())}));
return success();
Expand Down
12 changes: 6 additions & 6 deletions mlir/lib/Dialect/GPU/IR/GPUDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,15 +374,15 @@ void gpu::addAsyncDependency(Operation *op, Value token) {
return;
auto attrName =
OpTrait::AttrSizedOperandSegments<void>::getOperandSegmentSizeAttr();
auto sizeAttr = op->template getAttrOfType<DenseIntElementsAttr>(attrName);
auto sizeAttr = op->template getAttrOfType<DenseI32ArrayAttr>(attrName);

// Async dependencies is the only variadic operand.
if (!sizeAttr)
return;

SmallVector<int32_t, 8> sizes(sizeAttr.getValues<int32_t>());
SmallVector<int32_t, 8> sizes(sizeAttr.asArrayRef());
++sizes.front();
op->setAttr(attrName, Builder(op->getContext()).getI32VectorAttr(sizes));
op->setAttr(attrName, Builder(op->getContext()).getDenseI32ArrayAttr(sizes));
}

//===----------------------------------------------------------------------===//
Expand Down Expand Up @@ -416,7 +416,7 @@ void LaunchOp::build(OpBuilder &builder, OperationState &result,
segmentSizes.front() = asyncDependencies.size();
segmentSizes.back() = dynamicSharedMemorySize ? 1 : 0;
result.addAttribute(getOperandSegmentSizeAttr(),
builder.getI32VectorAttr(segmentSizes));
builder.getDenseI32ArrayAttr(segmentSizes));
}

KernelDim3 LaunchOp::getBlockIds() {
Expand Down Expand Up @@ -636,7 +636,7 @@ ParseResult LaunchOp::parse(OpAsmParser &parser, OperationState &result) {
segmentSizes.front() = asyncDependencies.size();
segmentSizes.back() = hasDynamicSharedMemorySize ? 1 : 0;
result.addAttribute(LaunchOp::getOperandSegmentSizeAttr(),
parser.getBuilder().getI32VectorAttr(segmentSizes));
parser.getBuilder().getDenseI32ArrayAttr(segmentSizes));
return success();
}

Expand Down Expand Up @@ -709,7 +709,7 @@ void LaunchFuncOp::build(OpBuilder &builder, OperationState &result,
segmentSizes[segmentSizes.size() - 2] = dynamicSharedMemorySize ? 1 : 0;
segmentSizes.back() = static_cast<int32_t>(kernelOperands.size());
result.addAttribute(getOperandSegmentSizeAttr(),
builder.getI32VectorAttr(segmentSizes));
builder.getDenseI32ArrayAttr(segmentSizes));
}

StringAttr LaunchFuncOp::getKernelModuleName() {
Expand Down
10 changes: 5 additions & 5 deletions mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1048,11 +1048,11 @@ ParseResult InvokeOp::parse(OpAsmParser &parser, OperationState &result) {
result.addOperands(normalOperands);
result.addOperands(unwindOperands);

result.addAttribute(
InvokeOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({static_cast<int32_t>(operands.size()),
static_cast<int32_t>(normalOperands.size()),
static_cast<int32_t>(unwindOperands.size())}));
result.addAttribute(InvokeOp::getOperandSegmentSizeAttr(),
builder.getDenseI32ArrayAttr(
{static_cast<int32_t>(operands.size()),
static_cast<int32_t>(normalOperands.size()),
static_cast<int32_t>(unwindOperands.size())}));
return success();
}

Expand Down
8 changes: 4 additions & 4 deletions mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,9 +233,9 @@ void MmaOp::build(OpBuilder &builder, OperationState &result, Type resultType,
result.addTypes(resultType);
result.addAttribute(
MmaOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({static_cast<int32_t>(operandA.size()),
static_cast<int32_t>(operandB.size()),
static_cast<int32_t>(operandC.size())}));
builder.getDenseI32ArrayAttr({static_cast<int32_t>(operandA.size()),
static_cast<int32_t>(operandB.size()),
static_cast<int32_t>(operandC.size())}));
}

// <operation> :=
Expand Down Expand Up @@ -326,7 +326,7 @@ ParseResult MmaOp::parse(OpAsmParser &parser, OperationState &result) {
if (!namedAttributes.empty())
result.addAttributes(namedAttributes);
result.addAttribute(MmaOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({
builder.getDenseI32ArrayAttr({
static_cast<int32_t>(frags[0].regs.size()),
static_cast<int32_t>(frags[1].regs.size()),
static_cast<int32_t>(frags[2].regs.size()),
Expand Down
6 changes: 3 additions & 3 deletions mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ static void buildStructuredOp(OpBuilder &b, OperationState &state,
state.addAttributes(attributes);
state.addAttribute(
"operand_segment_sizes",
b.getI32VectorAttr({static_cast<int32_t>(inputs.size()),
static_cast<int32_t>(outputs.size())}));
b.getDenseI32ArrayAttr({static_cast<int32_t>(inputs.size()),
static_cast<int32_t>(outputs.size())}));

// Create and fill the region of the structured operation.
Region &region = *state.addRegion();
Expand Down Expand Up @@ -157,7 +157,7 @@ parseCommonStructuredOpParts(OpAsmParser &parser, OperationState &result,
return failure();

result.addAttribute("operand_segment_sizes",
parser.getBuilder().getI32VectorAttr(
parser.getBuilder().getDenseI32ArrayAttr(
{static_cast<int32_t>(inputsOperands.size()),
static_cast<int32_t>(outputsOperands.size())}));
return success();
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ ParseResult ParallelOp::parse(OpAsmParser &parser, OperationState &result) {

result.addAttribute(
ParallelOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr(
builder.getDenseI32ArrayAttr(
{static_cast<int32_t>(async.has_value() ? 1 : 0),
static_cast<int32_t>(waitOperands.size()),
static_cast<int32_t>(numGangs.has_value() ? 1 : 0),
Expand Down Expand Up @@ -590,7 +590,7 @@ ParseResult LoopOp::parse(OpAsmParser &parser, OperationState &result) {
return failure();

result.addAttribute(LoopOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr(
builder.getDenseI32ArrayAttr(
{static_cast<int32_t>(gangNum.has_value() ? 1 : 0),
static_cast<int32_t>(gangStatic.has_value() ? 1 : 0),
static_cast<int32_t>(worker.has_value() ? 1 : 0),
Expand Down
16 changes: 8 additions & 8 deletions mlir/lib/Dialect/SCF/IR/SCF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2105,10 +2105,10 @@ void ParallelOp::build(
result.addOperands(initVals);
result.addAttribute(
ParallelOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({static_cast<int32_t>(lowerBounds.size()),
static_cast<int32_t>(upperBounds.size()),
static_cast<int32_t>(steps.size()),
static_cast<int32_t>(initVals.size())}));
builder.getDenseI32ArrayAttr({static_cast<int32_t>(lowerBounds.size()),
static_cast<int32_t>(upperBounds.size()),
static_cast<int32_t>(steps.size()),
static_cast<int32_t>(initVals.size())}));
result.addTypes(initVals.getTypes());

OpBuilder::InsertionGuard guard(builder);
Expand Down Expand Up @@ -2258,10 +2258,10 @@ ParseResult ParallelOp::parse(OpAsmParser &parser, OperationState &result) {
// Set `operand_segment_sizes` attribute.
result.addAttribute(
ParallelOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({static_cast<int32_t>(lower.size()),
static_cast<int32_t>(upper.size()),
static_cast<int32_t>(steps.size()),
static_cast<int32_t>(initVals.size())}));
builder.getDenseI32ArrayAttr({static_cast<int32_t>(lower.size()),
static_cast<int32_t>(upper.size()),
static_cast<int32_t>(steps.size()),
static_cast<int32_t>(initVals.size())}));

// Parse attributes.
if (parser.parseOptionalAttrDict(result.attributes) ||
Expand Down
8 changes: 4 additions & 4 deletions mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,10 +1579,10 @@ ParseResult spirv::BranchConditionalOp::parse(OpAsmParser &parser,
return failure();
result.addSuccessors(dest);
result.addOperands(falseOperands);
result.addAttribute(
spirv::BranchConditionalOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({1, static_cast<int32_t>(trueOperands.size()),
static_cast<int32_t>(falseOperands.size())}));
result.addAttribute(spirv::BranchConditionalOp::getOperandSegmentSizeAttr(),
builder.getDenseI32ArrayAttr(
{1, static_cast<int32_t>(trueOperands.size()),
static_cast<int32_t>(falseOperands.size())}));

return success();
}
Expand Down
16 changes: 8 additions & 8 deletions mlir/lib/Dialect/Vector/IR/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3015,10 +3015,10 @@ ParseResult TransferReadOp::parse(OpAsmParser &parser, OperationState &result) {
if (parser.resolveOperand(maskInfo, maskType, result.operands))
return failure();
}
result.addAttribute(
TransferReadOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({1, static_cast<int32_t>(indexInfo.size()), 1,
static_cast<int32_t>(hasMask.succeeded())}));
result.addAttribute(TransferReadOp::getOperandSegmentSizeAttr(),
builder.getDenseI32ArrayAttr(
{1, static_cast<int32_t>(indexInfo.size()), 1,
static_cast<int32_t>(hasMask.succeeded())}));
return parser.addTypeToList(vectorType, result.types);
}

Expand Down Expand Up @@ -3465,10 +3465,10 @@ ParseResult TransferWriteOp::parse(OpAsmParser &parser,
if (parser.resolveOperand(maskInfo, maskType, result.operands))
return failure();
}
result.addAttribute(
TransferWriteOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({1, 1, static_cast<int32_t>(indexInfo.size()),
static_cast<int32_t>(hasMask.succeeded())}));
result.addAttribute(TransferWriteOp::getOperandSegmentSizeAttr(),
builder.getDenseI32ArrayAttr(
{1, 1, static_cast<int32_t>(indexInfo.size()),
static_cast<int32_t>(hasMask.succeeded())}));
return failure(shapedType.isa<RankedTensorType>() &&
parser.addTypeToList(shapedType, result.types));
}
Expand Down
4 changes: 2 additions & 2 deletions mlir/lib/IR/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1860,11 +1860,11 @@ void AsmPrinter::Impl::printAttribute(Attribute attr,
}
} else if (auto denseArrayAttr = attr.dyn_cast<DenseArrayBaseAttr>()) {
typeElision = AttrTypeElision::Must;
os << "[:" << denseArrayAttr.getType().getElementType();
os << "array<" << denseArrayAttr.getType().getElementType() << ":";
if (denseArrayAttr.size())
os << " ";
denseArrayAttr.printWithoutBraces(os);
os << "]";
os << ">";
} else if (auto resourceAttr = attr.dyn_cast<DenseResourceElementsAttr>()) {
os << "dense_resource<";
printResourceHandle(resourceAttr.getRawHandle());
Expand Down
21 changes: 7 additions & 14 deletions mlir/lib/IR/Operation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -987,26 +987,19 @@ LogicalResult OpTrait::impl::verifyValueSizeAttr(Operation *op,
StringRef attrName,
StringRef valueGroupName,
size_t expectedCount) {
auto sizeAttr = op->getAttrOfType<DenseIntElementsAttr>(attrName);
auto sizeAttr = op->getAttrOfType<DenseI32ArrayAttr>(attrName);
if (!sizeAttr)
return op->emitOpError("requires 1D i32 elements attribute '")
return op->emitOpError("requires dense i32 array attribute '")
<< attrName << "'";

auto sizeAttrType = sizeAttr.getType();
if (sizeAttrType.getRank() != 1 ||
!sizeAttrType.getElementType().isInteger(32))
return op->emitOpError("requires 1D i32 elements attribute '")
<< attrName << "'";

if (llvm::any_of(sizeAttr.getValues<APInt>(), [](const APInt &element) {
return !element.isNonNegative();
}))
ArrayRef<int32_t> sizes = sizeAttr.asArrayRef();
if (llvm::any_of(sizes, [](int32_t element) { return element < 0; }))
return op->emitOpError("'")
<< attrName << "' attribute cannot have negative elements";

size_t totalCount = std::accumulate(
sizeAttr.begin(), sizeAttr.end(), 0,
[](unsigned all, const APInt &one) { return all + one.getZExtValue(); });
size_t totalCount =
std::accumulate(sizes.begin(), sizes.end(), 0,
[](unsigned all, int32_t one) { return all + one; });

if (totalCount != expectedCount)
return op->emitOpError()
Expand Down
23 changes: 11 additions & 12 deletions mlir/lib/IR/OperationSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ unsigned OperandRange::getBeginOperandIndex() const {
return base->getOperandNumber();
}

OperandRangeRange OperandRange::split(ElementsAttr segmentSizes) const {
OperandRangeRange OperandRange::split(DenseI32ArrayAttr segmentSizes) const {
return OperandRangeRange(*this, segmentSizes);
}

Expand All @@ -387,18 +387,18 @@ OperandRangeRange OperandRange::split(ElementsAttr segmentSizes) const {
OperandRangeRange::OperandRangeRange(OperandRange operands,
Attribute operandSegments)
: OperandRangeRange(OwnerT(operands.getBase(), operandSegments), 0,
operandSegments.cast<DenseElementsAttr>().size()) {}
operandSegments.cast<DenseI32ArrayAttr>().size()) {}

OperandRange OperandRangeRange::join() const {
const OwnerT &owner = getBase();
auto sizeData = owner.second.cast<DenseElementsAttr>().getValues<uint32_t>();
ArrayRef<int32_t> sizeData = owner.second.cast<DenseI32ArrayAttr>();
return OperandRange(owner.first,
std::accumulate(sizeData.begin(), sizeData.end(), 0));
}

OperandRange OperandRangeRange::dereference(const OwnerT &object,
ptrdiff_t index) {
auto sizeData = object.second.cast<DenseElementsAttr>().getValues<uint32_t>();
ArrayRef<int32_t> sizeData = object.second.cast<DenseI32ArrayAttr>();
uint32_t startIndex =
std::accumulate(sizeData.begin(), sizeData.begin() + index, 0);
return OperandRange(object.first + startIndex, *(sizeData.begin() + index));
Expand Down Expand Up @@ -490,11 +490,11 @@ void MutableOperandRange::updateLength(unsigned newLength) {

// Update any of the provided segment attributes.
for (OperandSegment &segment : operandSegments) {
auto attr = segment.second.getValue().cast<DenseIntElementsAttr>();
SmallVector<int32_t, 8> segments(attr.getValues<int32_t>());
auto attr = segment.second.getValue().cast<DenseI32ArrayAttr>();
SmallVector<int32_t, 8> segments(attr.asArrayRef());
segments[segment.first] += diff;
segment.second.setValue(
DenseIntElementsAttr::get(attr.getType(), segments));
DenseI32ArrayAttr::get(attr.getContext(), segments));
owner->setAttr(segment.second.getName(), segment.second.getValue());
}
}
Expand All @@ -506,21 +506,20 @@ MutableOperandRangeRange::MutableOperandRangeRange(
const MutableOperandRange &operands, NamedAttribute operandSegmentAttr)
: MutableOperandRangeRange(
OwnerT(operands, operandSegmentAttr), 0,
operandSegmentAttr.getValue().cast<DenseElementsAttr>().size()) {}
operandSegmentAttr.getValue().cast<DenseI32ArrayAttr>().size()) {}

MutableOperandRange MutableOperandRangeRange::join() const {
return getBase().first;
}

MutableOperandRangeRange::operator OperandRangeRange() const {
return OperandRangeRange(
getBase().first, getBase().second.getValue().cast<DenseElementsAttr>());
return OperandRangeRange(getBase().first, getBase().second.getValue());
}

MutableOperandRange MutableOperandRangeRange::dereference(const OwnerT &object,
ptrdiff_t index) {
auto sizeData =
object.second.getValue().cast<DenseElementsAttr>().getValues<uint32_t>();
ArrayRef<int32_t> sizeData =
object.second.getValue().cast<DenseI32ArrayAttr>();
uint32_t startIndex =
std::accumulate(sizeData.begin(), sizeData.begin() + index, 0);
return object.first.slice(
Expand Down
6 changes: 3 additions & 3 deletions mlir/lib/Rewrite/ByteCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1713,11 +1713,11 @@ executeGetOperandsResults(RangeT values, Operation *op, unsigned index,
LLVM_DEBUG(llvm::dbgs()
<< " * Extracting values from `" << attrSizedSegments << "`\n");

auto segmentAttr = op->getAttrOfType<DenseElementsAttr>(attrSizedSegments);
if (!segmentAttr || segmentAttr.getNumElements() <= index)
auto segmentAttr = op->getAttrOfType<DenseI32ArrayAttr>(attrSizedSegments);
if (!segmentAttr || segmentAttr.asArrayRef().size() <= index)
return nullptr;

auto segments = segmentAttr.getValues<int32_t>();
ArrayRef<int32_t> segments = segmentAttr;
unsigned startIndex =
std::accumulate(segments.begin(), segments.begin() + index, 0);
values = values.slice(startIndex, *std::next(segments.begin(), index));
Expand Down
2 changes: 1 addition & 1 deletion mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ LogicalResult Importer::processInstruction(llvm::Instruction *inst) {

if (brInst->isConditional()) {
state.addAttribute(LLVM::CondBrOp::getOperandSegmentSizeAttr(),
b.getI32VectorAttr(operandSegmentSizes));
b.getDenseI32ArrayAttr(operandSegmentSizes));
}

b.create(state);
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ func.func @wsloop(%arg0: index, %arg1: index, %arg2: index, %arg3: index, %arg4:
omp.parallel {
// CHECK: omp.wsloop for (%[[ARG6:.*]], %[[ARG7:.*]]) : i64 = (%[[ARG0]], %[[ARG1]]) to (%[[ARG2]], %[[ARG3]]) step (%[[ARG4]], %[[ARG5]]) {
"omp.wsloop"(%arg0, %arg1, %arg2, %arg3, %arg4, %arg5) ({
^bb0(%arg6: index, %arg7: index):
^bb0(%arg6: index, %arg7: index):
// CHECK-DAG: %[[CAST_ARG6:.*]] = builtin.unrealized_conversion_cast %[[ARG6]] : i64 to index
// CHECK-DAG: %[[CAST_ARG7:.*]] = builtin.unrealized_conversion_cast %[[ARG7]] : i64 to index
// CHECK: "test.payload"(%[[CAST_ARG6]], %[[CAST_ARG7]]) : (index, index) -> ()
"test.payload"(%arg6, %arg7) : (index, index) -> ()
omp.yield
}) {operand_segment_sizes = dense<[2, 2, 2, 0, 0, 0, 0]> : vector<7xi32>} : (index, index, index, index, index, index) -> ()
}) {operand_segment_sizes = array<i32: 2, 2, 2, 0, 0, 0, 0>} : (index, index, index, index, index, index) -> ()
omp.terminator
}
return
Expand Down
8 changes: 4 additions & 4 deletions mlir/test/Dialect/GPU/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ func.func @not_enough_sizes(%sz : index) {
// expected-error@+1 {{expected 6 or more operands, but found 5}}
"gpu.launch"(%sz, %sz, %sz, %sz, %sz) ({
gpu.return
}) {operand_segment_sizes = dense<[0, 1, 1, 1, 1, 1, 1, 0]> : vector<8xi32>} : (index, index, index, index, index) -> ()
}) {operand_segment_sizes = array<i32: 0, 1, 1, 1, 1, 1, 1, 0>} : (index, index, index, index, index) -> ()
return
}

Expand All @@ -16,7 +16,7 @@ func.func @no_region_attrs(%sz : index) {
^bb1(%bx: index, %by: index, %bz: index,
%tx: index, %ty: index, %tz: index):
gpu.terminator
}) {operand_segment_sizes = dense<[0, 1, 1, 1, 1, 1, 1, 0]> : vector<8xi32>} : (index, index, index, index, index, index) -> ()
}) {operand_segment_sizes = array<i32: 0, 1, 1, 1, 1, 1, 1, 0>} : (index, index, index, index, index, index) -> ()
return
}

Expand All @@ -38,7 +38,7 @@ func.func @launch_requires_gpu_return(%sz : index) {
func.func @launch_func_too_few_operands(%sz : index) {
// expected-error@+1 {{expected 6 or more operands}}
"gpu.launch_func"(%sz, %sz, %sz, %sz, %sz)
{operand_segment_sizes = dense<[0, 1, 1, 1, 1, 1, 0, 0]> : vector<8xi32>}
{operand_segment_sizes = array<i32: 0, 1, 1, 1, 1, 1, 0, 0>}
: (index, index, index, index, index) -> ()
return
}
Expand All @@ -57,7 +57,7 @@ module attributes {gpu.container_module} {
func.func @launch_func_missing_callee_attribute(%sz : index) {
// expected-error@+1 {{'gpu.launch_func' op requires attribute 'kernel'}}
"gpu.launch_func"(%sz, %sz, %sz, %sz, %sz, %sz)
{operand_segment_sizes = dense<[0, 1, 1, 1, 1, 1, 1, 0, 0]> : vector<9xi32>}
{operand_segment_sizes = array<i32: 0, 1, 1, 1, 1, 1, 1, 0, 0>}
: (index, index, index, index, index, index) -> ()
return
}
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Dialect/LLVMIR/dynamic-gep-index.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module attributes {dlti.dl_spec = #dlti.dl_spec<#dlti.dl_entry<i1, dense<8> : ve
// CHECK: %[[C0:.+]] = llvm.mlir.constant(0 : i32)
%0 = llvm.mlir.constant(0 : i32) : i32
// CHECK: llvm.getelementptr %[[ARG0]][%[[C0]], 1, %[[ARG1]]]
%1 = "llvm.getelementptr"(%arg0, %0, %arg1) {rawConstantIndices = [:i32 -2147483648, 1, -2147483648]} : (!llvm.ptr<struct<"my_struct", (struct<"sub_struct", (i32, i8)>, array<4 x i32>)>>, i32, i32) -> !llvm.ptr<i32>
%1 = "llvm.getelementptr"(%arg0, %0, %arg1) {rawConstantIndices = array<i32: -2147483648, 1, -2147483648>} : (!llvm.ptr<struct<"my_struct", (struct<"sub_struct", (i32, i8)>, array<4 x i32>)>>, i32, i32) -> !llvm.ptr<i32>
llvm.return
}
}
6 changes: 3 additions & 3 deletions mlir/test/Dialect/LLVMIR/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func.func @gep_non_function_type(%pos : i64, %base : !llvm.ptr<f32>) {

func.func @gep_too_few_dynamic(%base : !llvm.ptr<f32>) {
// expected-error@+1 {{expected as many dynamic indices as specified in 'rawConstantIndices'}}
%1 = "llvm.getelementptr"(%base) {rawConstantIndices = [:i32 -2147483648]} : (!llvm.ptr<f32>) -> !llvm.ptr<f32>
%1 = "llvm.getelementptr"(%base) {rawConstantIndices = array<i32: -2147483648>} : (!llvm.ptr<f32>) -> !llvm.ptr<f32>
}

// -----
Expand Down Expand Up @@ -414,15 +414,15 @@ func.func @insertvalue_wrong_nesting() {

func.func @insertvalue_invalid_type(%a : !llvm.array<1 x i32>) -> !llvm.array<1 x i32> {
// expected-error@+1 {{'llvm.insertvalue' op Type mismatch: cannot insert '!llvm.array<1 x i32>' into '!llvm.array<1 x i32>'}}
%b = "llvm.insertvalue"(%a, %a) {position = [:i64 0]} : (!llvm.array<1 x i32>, !llvm.array<1 x i32>) -> !llvm.array<1 x i32>
%b = "llvm.insertvalue"(%a, %a) {position = array<i64: 0>} : (!llvm.array<1 x i32>, !llvm.array<1 x i32>) -> !llvm.array<1 x i32>
return %b : !llvm.array<1 x i32>
}

// -----

func.func @extractvalue_invalid_type(%a : !llvm.array<4 x vector<8xf32>>) -> !llvm.array<4 x vector<8xf32>> {
// expected-error@+1 {{'llvm.extractvalue' op Type mismatch: extracting from '!llvm.array<4 x vector<8xf32>>' should produce 'vector<8xf32>' but this op returns '!llvm.array<4 x vector<8xf32>>'}}
%b = "llvm.extractvalue"(%a) {position = [:i64 1]}
%b = "llvm.extractvalue"(%a) {position = array<i64: 1>}
: (!llvm.array<4 x vector<8xf32>>) -> !llvm.array<4 x vector<8xf32>>
return %b : !llvm.array<4 x vector<8xf32>>
}
Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Dialect/Linalg/named-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -742,7 +742,7 @@ func.func @conv_interface_wrong_input_indexing_map(
%1 = "arith.mulf"(%arg3, %arg4) : (f32, f32) -> f32
%2 = "arith.addf"(%arg5, %1) : (f32, f32) -> f32
"linalg.yield"(%2) : (f32) -> ()
}) {dilations = dense<1> : tensor<2xi64>, linalg.memoized_indexing_maps = [#map0, #map1, #map2], operand_segment_sizes = dense<[2, 1]> : vector<2xi32>, strides = dense<2> : tensor<2xi64>} : (tensor<?x?x?x?xf32>, tensor<?x?x?x?xf32>, tensor<?x?x?x?xf32>) -> tensor<?x?x?x?xf32>
}) {dilations = dense<1> : tensor<2xi64>, linalg.memoized_indexing_maps = [#map0, #map1, #map2], operand_segment_sizes = array<i32: 2, 1>, strides = dense<2> : tensor<2xi64>} : (tensor<?x?x?x?xf32>, tensor<?x?x?x?xf32>, tensor<?x?x?x?xf32>) -> tensor<?x?x?x?xf32>
return %0 : tensor<?x?x?x?xf32>
}

Expand All @@ -759,6 +759,6 @@ func.func @conv_interface_wrong_num_operands(
%1 = "arith.mulf"(%arg3, %arg4) : (f32, f32) -> f32
%2 = "arith.addf"(%arg5, %1) : (f32, f32) -> f32
"linalg.yield"(%2) : (f32) -> ()
}) {dilations = dense<1> : tensor<2xi64>, linalg.memoized_indexing_maps = [#map0, #map1, #map2], operand_segment_sizes = dense<[2, 1]> : vector<2xi32>, strides = dense<1> : tensor<2xi64>} : (tensor<?x?x?x?xf32>, tensor<?x?x?x?x?xf32>, tensor<?x?x?x?xf32>) -> tensor<?x?x?x?xf32>
}) {dilations = dense<1> : tensor<2xi64>, linalg.memoized_indexing_maps = [#map0, #map1, #map2], operand_segment_sizes = array<i32: 2, 1>, strides = dense<1> : tensor<2xi64>} : (tensor<?x?x?x?xf32>, tensor<?x?x?x?x?xf32>, tensor<?x?x?x?xf32>) -> tensor<?x?x?x?xf32>
return %0 : tensor<?x?x?x?xf32>
}
20 changes: 10 additions & 10 deletions mlir/test/Dialect/OpenMP/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ func.func @omp_simdloop(%lb : index, %ub : index, %step : i32) -> () {
"omp.simdloop" (%lb, %ub, %step) ({
^bb0(%iv: index):
omp.yield
}) {operand_segment_sizes = dense<[1,1,1,0]> : vector<4xi32>} :
(index, index, i32) -> ()
}) {operand_segment_sizes = array<i32: 1,1,1,0>} :
(index, index, i32) -> ()

return
}
Expand Down Expand Up @@ -985,7 +985,7 @@ func.func @omp_sections(%data_var : memref<i32>) -> () {
// expected-error @below {{expected equal sizes for allocate and allocator variables}}
"omp.sections" (%data_var) ({
omp.terminator
}) {operand_segment_sizes = dense<[0,1,0]> : vector<3xi32>} : (memref<i32>) -> ()
}) {operand_segment_sizes = array<i32: 0,1,0>} : (memref<i32>) -> ()
return
}

Expand All @@ -995,7 +995,7 @@ func.func @omp_sections(%data_var : memref<i32>) -> () {
// expected-error @below {{expected as many reduction symbol references as reduction variables}}
"omp.sections" (%data_var) ({
omp.terminator
}) {operand_segment_sizes = dense<[1,0,0]> : vector<3xi32>} : (memref<i32>) -> ()
}) {operand_segment_sizes = array<i32: 1,0,0>} : (memref<i32>) -> ()
return
}

Expand Down Expand Up @@ -1110,7 +1110,7 @@ func.func @omp_single(%data_var : memref<i32>) -> () {
// expected-error @below {{expected equal sizes for allocate and allocator variables}}
"omp.single" (%data_var) ({
omp.barrier
}) {operand_segment_sizes = dense<[1,0]> : vector<2xi32>} : (memref<i32>) -> ()
}) {operand_segment_sizes = array<i32: 1,0>} : (memref<i32>) -> ()
return
}

Expand Down Expand Up @@ -1302,7 +1302,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) {
"omp.taskloop"(%lb, %ub, %ub, %lb, %step, %step, %testmemref) ({
^bb0(%arg3: i32, %arg4: i32):
"omp.terminator"() : () -> ()
}) {operand_segment_sizes = dense<[2, 2, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0]> : vector<12xi32>} : (i32, i32, i32, i32, i32, i32, memref<i32>) -> ()
}) {operand_segment_sizes = array<i32: 2, 2, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0>} : (i32, i32, i32, i32, i32, i32, memref<i32>) -> ()
return
}

Expand All @@ -1315,7 +1315,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) {
"omp.taskloop"(%lb, %ub, %ub, %lb, %step, %step, %testf32, %testf32_2) ({
^bb0(%arg3: i32, %arg4: i32):
"omp.terminator"() : () -> ()
}) {operand_segment_sizes = dense<[2, 2, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0]> : vector<12xi32>, reductions = [@add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>, !llvm.ptr<f32>) -> ()
}) {operand_segment_sizes = array<i32: 2, 2, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0>, reductions = [@add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>, !llvm.ptr<f32>) -> ()
return
}

Expand All @@ -1328,7 +1328,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) {
"omp.taskloop"(%lb, %ub, %ub, %lb, %step, %step, %testf32) ({
^bb0(%arg3: i32, %arg4: i32):
"omp.terminator"() : () -> ()
}) {operand_segment_sizes = dense<[2, 2, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0]> : vector<12xi32>, reductions = [@add_f32, @add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>) -> ()
}) {operand_segment_sizes = array<i32: 2, 2, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0>, reductions = [@add_f32, @add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>) -> ()
return
}

Expand All @@ -1341,7 +1341,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) {
"omp.taskloop"(%lb, %ub, %ub, %lb, %step, %step, %testf32, %testf32_2) ({
^bb0(%arg3: i32, %arg4: i32):
"omp.terminator"() : () -> ()
}) {in_reductions = [@add_f32], operand_segment_sizes = dense<[2, 2, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0]> : vector<12xi32>} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>, !llvm.ptr<f32>) -> ()
}) {in_reductions = [@add_f32], operand_segment_sizes = array<i32: 2, 2, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0>} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>, !llvm.ptr<f32>) -> ()
return
}

Expand All @@ -1354,7 +1354,7 @@ func.func @taskloop(%lb: i32, %ub: i32, %step: i32) {
"omp.taskloop"(%lb, %ub, %ub, %lb, %step, %step, %testf32_2) ({
^bb0(%arg3: i32, %arg4: i32):
"omp.terminator"() : () -> ()
}) {in_reductions = [@add_f32, @add_f32], operand_segment_sizes = dense<[2, 2, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0]> : vector<12xi32>} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>) -> ()
}) {in_reductions = [@add_f32, @add_f32], operand_segment_sizes = array<i32: 2, 2, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0>} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>) -> ()
return
}

Expand Down
30 changes: 15 additions & 15 deletions mlir/test/Dialect/OpenMP/ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func.func @omp_parallel(%data_var : memref<i32>, %if_cond : i1, %num_threads : i
// CHECK: omp.parallel num_threads(%{{.*}} : i32) allocate(%{{.*}} : memref<i32> -> %{{.*}} : memref<i32>)
"omp.parallel"(%num_threads, %data_var, %data_var) ({
omp.terminator
}) {operand_segment_sizes = dense<[0,1,1,1,0]> : vector<5xi32>} : (i32, memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = array<i32: 0,1,1,1,0>} : (i32, memref<i32>, memref<i32>) -> ()

// CHECK: omp.barrier
omp.barrier
Expand All @@ -68,22 +68,22 @@ func.func @omp_parallel(%data_var : memref<i32>, %if_cond : i1, %num_threads : i
// CHECK: omp.parallel if(%{{.*}}) allocate(%{{.*}} : memref<i32> -> %{{.*}} : memref<i32>)
"omp.parallel"(%if_cond, %data_var, %data_var) ({
omp.terminator
}) {operand_segment_sizes = dense<[1,0,1,1,0]> : vector<5xi32>} : (i1, memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = array<i32: 1,0,1,1,0>} : (i1, memref<i32>, memref<i32>) -> ()

// test without allocate
// CHECK: omp.parallel if(%{{.*}}) num_threads(%{{.*}} : i32)
"omp.parallel"(%if_cond, %num_threads) ({
omp.terminator
}) {operand_segment_sizes = dense<[1,1,0,0,0]> : vector<5xi32>} : (i1, i32) -> ()
}) {operand_segment_sizes = array<i32: 1,1,0,0,0>} : (i1, i32) -> ()

omp.terminator
}) {operand_segment_sizes = dense<[1,1,1,1,0]> : vector<5xi32>, proc_bind_val = #omp<procbindkind spread>} : (i1, i32, memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = array<i32: 1,1,1,1,0>, proc_bind_val = #omp<procbindkind spread>} : (i1, i32, memref<i32>, memref<i32>) -> ()

// test with multiple parameters for single variadic argument
// CHECK: omp.parallel allocate(%{{.*}} : memref<i32> -> %{{.*}} : memref<i32>)
"omp.parallel" (%data_var, %data_var) ({
omp.terminator
}) {operand_segment_sizes = dense<[0,0,1,1,0]> : vector<5xi32>} : (memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = array<i32: 0,0,1,1,0>} : (memref<i32>, memref<i32>) -> ()

return
}
Expand Down Expand Up @@ -141,39 +141,39 @@ func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memre
"omp.wsloop" (%lb, %ub, %step) ({
^bb0(%iv: index):
omp.yield
}) {operand_segment_sizes = dense<[1,1,1,0,0,0,0]> : vector<7xi32>, ordered_val = 1} :
}) {operand_segment_sizes = array<i32: 1,1,1,0,0,0,0>, ordered_val = 1} :
(index, index, index) -> ()

// CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref<i32>) schedule(static)
// CHECK-SAMe: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
"omp.wsloop" (%lb, %ub, %step, %data_var, %linear_var) ({
^bb0(%iv: index):
omp.yield
}) {operand_segment_sizes = dense<[1,1,1,1,1,0,0]> : vector<7xi32>, schedule_val = #omp<schedulekind static>} :
}) {operand_segment_sizes = array<i32: 1,1,1,1,1,0,0>, schedule_val = #omp<schedulekind static>} :
(index, index, index, memref<i32>, i32) -> ()

// CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref<i32>, %{{.*}} = %{{.*}} : memref<i32>) schedule(static)
// CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
"omp.wsloop" (%lb, %ub, %step, %data_var, %data_var, %linear_var, %linear_var) ({
^bb0(%iv: index):
omp.yield
}) {operand_segment_sizes = dense<[1,1,1,2,2,0,0]> : vector<7xi32>, schedule_val = #omp<schedulekind static>} :
}) {operand_segment_sizes = array<i32: 1,1,1,2,2,0,0>, schedule_val = #omp<schedulekind static>} :
(index, index, index, memref<i32>, memref<i32>, i32, i32) -> ()

// CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref<i32>) schedule(dynamic = %{{.*}}) ordered(2)
// CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
"omp.wsloop" (%lb, %ub, %step, %data_var, %linear_var, %chunk_var) ({
^bb0(%iv: index):
omp.yield
}) {operand_segment_sizes = dense<[1,1,1,1,1,0,1]> : vector<7xi32>, schedule_val = #omp<schedulekind dynamic>, ordered_val = 2} :
}) {operand_segment_sizes = array<i32: 1,1,1,1,1,0,1>, schedule_val = #omp<schedulekind dynamic>, ordered_val = 2} :
(index, index, index, memref<i32>, i32, i32) -> ()

// CHECK: omp.wsloop schedule(auto) nowait
// CHECK-SAME: for (%{{.*}}) : index = (%{{.*}}) to (%{{.*}}) step (%{{.*}})
"omp.wsloop" (%lb, %ub, %step) ({
^bb0(%iv: index):
omp.yield
}) {operand_segment_sizes = dense<[1,1,1,0,0,0,0]> : vector<7xi32>, nowait, schedule_val = #omp<schedulekind auto>} :
}) {operand_segment_sizes = array<i32: 1,1,1,0,0,0,0>, nowait, schedule_val = #omp<schedulekind auto>} :
(index, index, index) -> ()

return
Expand Down Expand Up @@ -333,8 +333,8 @@ func.func @omp_simdloop(%lb : index, %ub : index, %step : index) -> () {
"omp.simdloop" (%lb, %ub, %step) ({
^bb0(%iv: index):
omp.yield
}) {operand_segment_sizes = dense<[1,1,1,0]> : vector<4xi32>} :
(index, index, index) -> ()
}) {operand_segment_sizes = array<i32: 1,1,1,0>} :
(index, index, index) -> ()

return
}
Expand Down Expand Up @@ -383,7 +383,7 @@ func.func @omp_target(%if_cond : i1, %device : si32, %num_threads : i32) -> ()
"omp.target"(%if_cond, %device, %num_threads) ({
// CHECK: omp.terminator
omp.terminator
}) {nowait, operand_segment_sizes = dense<[1,1,1]>: vector<3xi32>} : ( i1, si32, i32 ) -> ()
}) {nowait, operand_segment_sizes = array<i32: 1,1,1>} : ( i1, si32, i32 ) -> ()

// CHECK: omp.barrier
omp.barrier
Expand Down Expand Up @@ -1227,13 +1227,13 @@ func.func @omp_sectionsop(%data_var1 : memref<i32>, %data_var2 : memref<i32>,
"omp.sections" (%data_var1, %data_var1) ({
// CHECK: omp.terminator
omp.terminator
}) {operand_segment_sizes = dense<[0,1,1]> : vector<3xi32>} : (memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = array<i32: 0,1,1>} : (memref<i32>, memref<i32>) -> ()

// CHECK: omp.sections reduction(@add_f32 -> %{{.*}} : !llvm.ptr<f32>)
"omp.sections" (%redn_var) ({
// CHECK: omp.terminator
omp.terminator
}) {operand_segment_sizes = dense<[1,0,0]> : vector<3xi32>, reductions=[@add_f32]} : (!llvm.ptr<f32>) -> ()
}) {operand_segment_sizes = array<i32: 1,0,0>, reductions=[@add_f32]} : (!llvm.ptr<f32>) -> ()

// CHECK: omp.sections nowait {
omp.sections nowait {
Expand Down
10 changes: 5 additions & 5 deletions mlir/test/Dialect/PDL/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pdl.pattern : benefit(1) {
// expected-error@below {{expected the same number of attribute values and attribute names, got 1 names and 0 values}}
%op = "pdl.operation"() {
attributeNames = ["attr"],
operand_segment_sizes = dense<0> : vector<3xi32>
operand_segment_sizes = array<i32: 0, 0, 0>
} : () -> (!pdl.operation)
rewrite %op with "rewriter"
}
Expand Down Expand Up @@ -230,7 +230,7 @@ pdl.pattern : benefit(1) {

// expected-error@below {{expected no replacement values to be provided when the replacement operation is present}}
"pdl.replace"(%root, %newOp, %newResult) {
operand_segment_sizes = dense<1> : vector<3xi32>
operand_segment_sizes = array<i32: 1, 1, 1>
} : (!pdl.operation, !pdl.operation, !pdl.value) -> ()
}
}
Expand Down Expand Up @@ -259,7 +259,7 @@ pdl.pattern : benefit(1) {

// expected-error@below {{expected rewrite region to be non-empty if external name is not specified}}
"pdl.rewrite"(%op) ({}) {
operand_segment_sizes = dense<[1,0]> : vector<2xi32>
operand_segment_sizes = array<i32: 1,0>
} : (!pdl.operation) -> ()
}

Expand All @@ -272,7 +272,7 @@ pdl.pattern : benefit(1) {
"pdl.rewrite"(%op, %op) ({
^bb1:
}) {
operand_segment_sizes = dense<1> : vector<2xi32>
operand_segment_sizes = array<i32: 1, 1>
}: (!pdl.operation, !pdl.operation) -> ()
}

Expand All @@ -286,7 +286,7 @@ pdl.pattern : benefit(1) {
^bb1:
}) {
name = "foo",
operand_segment_sizes = dense<[1,0]> : vector<2xi32>
operand_segment_sizes = array<i32: 1,0>
} : (!pdl.operation) -> ()
}

Expand Down
3 changes: 1 addition & 2 deletions mlir/test/Dialect/PDLInterp/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ pdl_interp.func @rewriter() {
inferredResultTypes,
inputAttributeNames = [],
name = "foo.op",
operand_segment_sizes = dense<[0, 0, 1]> : vector<3xi32>
operand_segment_sizes = array<i32: 0, 0, 1>
} : (!pdl.type) -> (!pdl.operation)
pdl_interp.finalize
}

4 changes: 2 additions & 2 deletions mlir/test/Dialect/SCF/invalid.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func.func @parallel_body_arguments_wrong_type(
"scf.parallel"(%arg0, %arg1, %arg2) ({
^bb0(%i0: f32):
scf.yield
}) {operand_segment_sizes = dense<[1, 1, 1, 0]>: vector<4xi32>}: (index, index, index) -> ()
}) {operand_segment_sizes = array<i32: 1, 1, 1, 0>}: (index, index, index) -> ()
return
}

Expand All @@ -143,7 +143,7 @@ func.func @parallel_body_wrong_number_of_arguments(
"scf.parallel"(%arg0, %arg1, %arg2) ({
^bb0(%i0: index, %i1: index):
scf.yield
}) {operand_segment_sizes = dense<[1, 1, 1, 0]>: vector<4xi32>}: (index, index, index) -> ()
}) {operand_segment_sizes = array<i32: 1, 1, 1, 0>}: (index, index, index) -> ()
return
}

Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func.func @wrong_condition_type() -> () {
func.func @wrong_accessor_count() -> () {
%true = spv.Constant true
// expected-error @+1 {{requires 2 successors but found 1}}
"spv.BranchConditional"(%true)[^one] {operand_segment_sizes = dense<[1, 0, 0]>: vector<3xi32>} : (i1) -> ()
"spv.BranchConditional"(%true)[^one] {operand_segment_sizes = array<i32: 1, 0, 0>} : (i1) -> ()
^one:
spv.Return
^two:
Expand All @@ -130,7 +130,7 @@ func.func @wrong_number_of_weights() -> () {
%true = spv.Constant true
// expected-error @+1 {{must have exactly two branch weights}}
"spv.BranchConditional"(%true)[^one, ^two] {branch_weights = [1 : i32, 2 : i32, 3 : i32],
operand_segment_sizes = dense<[1, 0, 0]>: vector<3xi32>} : (i1) -> ()
operand_segment_sizes = array<i32: 1, 0, 0>} : (i1) -> ()
^one:
spv.Return
^two:
Expand Down
56 changes: 28 additions & 28 deletions mlir/test/IR/attribute.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -522,34 +522,34 @@ func.func @simple_scalar_example() {

// CHECK-LABEL: func @dense_array_attr
func.func @dense_array_attr() attributes {
// CHECK-SAME: emptyf32attr = [:f32],
emptyf32attr = [:f32],
// CHECK-SAME: emptyf64attr = [:f64],
emptyf64attr = [:f64],
// CHECK-SAME: emptyi16attr = [:i16],
emptyi16attr = [:i16],
// CHECK-SAME: emptyi1attr = [:i1],
emptyi1attr = [:i1],
// CHECK-SAME: emptyi32attr = [:i32],
emptyi32attr = [:i32],
// CHECK-SAME: emptyi64attr = [:i64],
emptyi64attr = [:i64],
// CHECK-SAME: emptyi8attr = [:i8],
emptyi8attr = [:i8],
// CHECK-SAME: f32attr = [:f32 1.024000e+03, 4.530000e+02, -6.435000e+03],
f32attr = [:f32 1024., 453., -6435.],
// CHECK-SAME: f64attr = [:f64 -1.420000e+02],
f64attr = [:f64 -142.],
// CHECK-SAME: i16attr = [:i16 3, 5, -4, 10],
i16attr = [:i16 3, 5, -4, 10],
// CHECK-SAME: i1attr = [:i1 true, false, true],
i1attr = [:i1 true, false, true],
// CHECK-SAME: i32attr = [:i32 1024, 453, -6435],
i32attr = [:i32 1024, 453, -6435],
// CHECK-SAME: i64attr = [:i64 -142],
i64attr = [:i64 -142],
// CHECK-SAME: i8attr = [:i8 1, -2, 3]
i8attr = [:i8 1, -2, 3]
// CHECK-SAME: emptyf32attr = array<f32:>,
emptyf32attr = array<f32:>,
// CHECK-SAME: emptyf64attr = array<f64:>,
emptyf64attr = array<f64:>,
// CHECK-SAME: emptyi16attr = array<i16:>,
emptyi16attr = array<i16:>,
// CHECK-SAME: emptyi1attr = array<i1:>,
emptyi1attr = array<i1:>,
// CHECK-SAME: emptyi32attr = array<i32:>,
emptyi32attr = array<i32:>,
// CHECK-SAME: emptyi64attr = array<i64:>,
emptyi64attr = array<i64:>,
// CHECK-SAME: emptyi8attr = array<i8:>,
emptyi8attr = array<i8:>,
// CHECK-SAME: f32attr = array<f32: 1.024000e+03, 4.530000e+02, -6.435000e+03>,
f32attr = array<f32: 1024., 453., -6435.>,
// CHECK-SAME: f64attr = array<f64: -1.420000e+02>,
f64attr = array<f64: -142.>,
// CHECK-SAME: i16attr = array<i16: 3, 5, -4, 10>,
i16attr = array<i16: 3, 5, -4, 10>,
// CHECK-SAME: i1attr = array<i1: true, false, true>,
i1attr = array<i1: true, false, true>,
// CHECK-SAME: i32attr = array<i32: 1024, 453, -6435>,
i32attr = array<i32: 1024, 453, -6435>,
// CHECK-SAME: i64attr = array<i64: -142>,
i64attr = array<i64: -142>,
// CHECK-SAME: i8attr = array<i8: 1, -2, 3>
i8attr = array<i8: 1, -2, 3>
} {
// CHECK: test.dense_array_attr
test.dense_array_attr
Expand Down
14 changes: 7 additions & 7 deletions mlir/test/IR/elements-attr-interface.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ arith.constant dense<[10, 11, 12, 13, 14]> : tensor<5xi64>
arith.constant dense<> : tensor<0xi64>

// expected-error@below {{Test iterating `bool`: true, false, true, false, true, false}}
arith.constant [:i1 true, false, true, false, true, false]
arith.constant array<i1: true, false, true, false, true, false>
// expected-error@below {{Test iterating `int8_t`: 10, 11, -12, 13, 14}}
arith.constant [:i8 10, 11, -12, 13, 14]
arith.constant array<i8: 10, 11, -12, 13, 14>
// expected-error@below {{Test iterating `int16_t`: 10, 11, -12, 13, 14}}
arith.constant [:i16 10, 11, -12, 13, 14]
arith.constant array<i16: 10, 11, -12, 13, 14>
// expected-error@below {{Test iterating `int32_t`: 10, 11, -12, 13, 14}}
arith.constant [:i32 10, 11, -12, 13, 14]
arith.constant array<i32: 10, 11, -12, 13, 14>
// expected-error@below {{Test iterating `int64_t`: 10, 11, -12, 13, 14}}
arith.constant [:i64 10, 11, -12, 13, 14]
arith.constant array<i64: 10, 11, -12, 13, 14>
// expected-error@below {{Test iterating `float`: 10.00, 11.00, -12.00, 13.00, 14.00}}
arith.constant [:f32 10., 11., -12., 13., 14.]
arith.constant array<f32: 10., 11., -12., 13., 14.>
// expected-error@below {{Test iterating `double`: 10.00, 11.00, -12.00, 13.00, 14.00}}
arith.constant [:f64 10., 11., -12., 13., 14.]
arith.constant array<f64: 10., 11., -12., 13., 14.>

// Check that we handle an external constant parsed from the config.
// expected-error@below {{Test iterating `int64_t`: unable to iterate type}}
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/IR/parser.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ func.func @verbose_terminators() -> (i1, i17) {

^bb1(%x : i1, %y : i17):
// CHECK: cf.cond_br %{{.*}}, ^bb2(%{{.*}} : i17), ^bb3(%{{.*}}, %{{.*}} : i1, i17)
"cf.cond_br"(%x, %y, %x, %y) [^bb2, ^bb3] {operand_segment_sizes = dense<[1, 1, 2]>: vector<3xi32>} : (i1, i17, i1, i17) -> ()
"cf.cond_br"(%x, %y, %x, %y) [^bb2, ^bb3] {operand_segment_sizes = array<i32: 1, 1, 2>} : (i1, i17, i1, i17) -> ()

^bb2(%a : i17):
%true = arith.constant true
Expand Down
45 changes: 16 additions & 29 deletions mlir/test/IR/traits.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -375,114 +375,101 @@ func.func private @foo()
// -----

func.func @failedMissingOperandSizeAttr(%arg: i32) {
// expected-error @+1 {{requires 1D i32 elements attribute 'operand_segment_sizes'}}
// expected-error @+1 {{requires dense i32 array attribute 'operand_segment_sizes'}}
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) : (i32, i32, i32, i32) -> ()
}

// -----

func.func @failedOperandSizeAttrWrongType(%arg: i32) {
// expected-error @+1 {{requires 1D i32 elements attribute 'operand_segment_sizes'}}
// expected-error @+1 {{requires dense i32 array attribute 'operand_segment_sizes'}}
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = 10} : (i32, i32, i32, i32) -> ()
}

// -----

func.func @failedOperandSizeAttrWrongRank(%arg: i32) {
// expected-error @+1 {{requires 1D i32 elements attribute 'operand_segment_sizes'}}
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[[1, 1], [1, 1]]>: vector<2x2xi32>} : (i32, i32, i32, i32) -> ()
}

// -----

func.func @failedOperandSizeAttrWrongElementType(%arg: i32) {
// expected-error @+1 {{requires 1D i32 elements attribute 'operand_segment_sizes'}}
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[1, 1, 1, 1]>: vector<4xi64>} : (i32, i32, i32, i32) -> ()
// expected-error @+1 {{requires dense i32 array attribute 'operand_segment_sizes'}}
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = array<i64: 1, 1, 1, 1>} : (i32, i32, i32, i32) -> ()
}

// -----

func.func @failedOperandSizeAttrNegativeValue(%arg: i32) {
// expected-error @+1 {{'operand_segment_sizes' attribute cannot have negative elements}}
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[1, 1, -1, 1]>: vector<4xi32>} : (i32, i32, i32, i32) -> ()
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = array<i32: 1, 1, -1, 1>} : (i32, i32, i32, i32) -> ()
}

// -----

func.func @failedOperandSizeAttrWrongTotalSize(%arg: i32) {
// expected-error @+1 {{operand count (4) does not match with the total size (3) specified in attribute 'operand_segment_sizes'}}
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[0, 1, 1, 1]>: vector<4xi32>} : (i32, i32, i32, i32) -> ()
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = array<i32: 0, 1, 1, 1>} : (i32, i32, i32, i32) -> ()
}

// -----

func.func @failedOperandSizeAttrWrongCount(%arg: i32) {
// expected-error @+1 {{'operand_segment_sizes' attribute for specifying operand segments must have 4 elements}}
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[2, 1, 1]>: vector<3xi32>} : (i32, i32, i32, i32) -> ()
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = array<i32: 2, 1, 1>} : (i32, i32, i32, i32) -> ()
}

// -----

func.func @succeededOperandSizeAttr(%arg: i32) {
// CHECK: test.attr_sized_operands
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[0, 2, 1, 1]>: vector<4xi32>} : (i32, i32, i32, i32) -> ()
"test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = array<i32: 0, 2, 1, 1>} : (i32, i32, i32, i32) -> ()
return
}

// -----

func.func @failedMissingResultSizeAttr() {
// expected-error @+1 {{requires 1D i32 elements attribute 'result_segment_sizes'}}
// expected-error @+1 {{requires dense i32 array attribute 'result_segment_sizes'}}
%0:4 = "test.attr_sized_results"() : () -> (i32, i32, i32, i32)
}

// -----

func.func @failedResultSizeAttrWrongType() {
// expected-error @+1 {{requires 1D i32 elements attribute 'result_segment_sizes'}}
// expected-error @+1 {{requires dense i32 array attribute 'result_segment_sizes'}}
%0:4 = "test.attr_sized_results"() {result_segment_sizes = 10} : () -> (i32, i32, i32, i32)
}

// -----

func.func @failedResultSizeAttrWrongRank() {
// expected-error @+1 {{requires 1D i32 elements attribute 'result_segment_sizes'}}
%0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[[1, 1], [1, 1]]>: vector<2x2xi32>} : () -> (i32, i32, i32, i32)
}

// -----

func.func @failedResultSizeAttrWrongElementType() {
// expected-error @+1 {{requires 1D i32 elements attribute 'result_segment_sizes'}}
%0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[1, 1, 1, 1]>: vector<4xi64>} : () -> (i32, i32, i32, i32)
// expected-error @+1 {{requires dense i32 array attribute 'result_segment_sizes'}}
%0:4 = "test.attr_sized_results"() {result_segment_sizes = array<i64: 1, 1, 1, 1>} : () -> (i32, i32, i32, i32)
}

// -----

func.func @failedResultSizeAttrNegativeValue() {
// expected-error @+1 {{'result_segment_sizes' attribute cannot have negative elements}}
%0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[1, 1, -1, 1]>: vector<4xi32>} : () -> (i32, i32, i32, i32)
%0:4 = "test.attr_sized_results"() {result_segment_sizes = array<i32: 1, 1, -1, 1>} : () -> (i32, i32, i32, i32)
}

// -----

func.func @failedResultSizeAttrWrongTotalSize() {
// expected-error @+1 {{result count (4) does not match with the total size (3) specified in attribute 'result_segment_sizes'}}
%0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[0, 1, 1, 1]>: vector<4xi32>} : () -> (i32, i32, i32, i32)
%0:4 = "test.attr_sized_results"() {result_segment_sizes = array<i32: 0, 1, 1, 1>} : () -> (i32, i32, i32, i32)
}

// -----

func.func @failedResultSizeAttrWrongCount() {
// expected-error @+1 {{'result_segment_sizes' attribute for specifying result segments must have 4 elements, but got 3}}
%0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[2, 1, 1]>: vector<3xi32>} : () -> (i32, i32, i32, i32)
%0:4 = "test.attr_sized_results"() {result_segment_sizes = array<i32: 2, 1, 1>} : () -> (i32, i32, i32, i32)
}

// -----

func.func @succeededResultSizeAttr() {
// CHECK: test.attr_sized_results
%0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[0, 2, 1, 1]>: vector<4xi32>} : () -> (i32, i32, i32, i32)
%0:4 = "test.attr_sized_results"() {result_segment_sizes = array<i32: 0, 2, 1, 1>} : () -> (i32, i32, i32, i32)
return
}

Expand Down
4 changes: 2 additions & 2 deletions mlir/test/Rewrite/pdl-bytecode.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -1051,7 +1051,7 @@ module @patterns {
// CHECK-NEXT: "test.success"(%[[INPUTS]]#4) : (i32) -> ()
module @ir attributes { test.get_operands_2 } {
%inputs:5 = "test.producer"() : () -> (i32, i32, i32, i32, i32)
"test.attr_sized_operands"(%inputs#0, %inputs#1, %inputs#2, %inputs#3, %inputs#4) {operand_segment_sizes = dense<[0, 4, 1, 0]> : vector<4xi32>} : (i32, i32, i32, i32, i32) -> ()
"test.attr_sized_operands"(%inputs#0, %inputs#1, %inputs#2, %inputs#3, %inputs#4) {operand_segment_sizes = array<i32: 0, 4, 1, 0>} : (i32, i32, i32, i32, i32) -> ()
}

// -----
Expand Down Expand Up @@ -1204,7 +1204,7 @@ module @patterns {
// CHECK: %[[RESULTS_2_SINGLE:.*]] = "test.success"() : () -> i32
// CHECK: "test.consumer"(%[[RESULTS_1]]#0, %[[RESULTS_1]]#1, %[[RESULTS_1]]#2, %[[RESULTS_1]]#3, %[[RESULTS_2]]) : (i32, i32, i32, i32, i32) -> ()
module @ir attributes { test.get_results_2 } {
%results:5 = "test.attr_sized_results"() {result_segment_sizes = dense<[0, 4, 1, 0]> : vector<4xi32>} : () -> (i32, i32, i32, i32, i32)
%results:5 = "test.attr_sized_results"() {result_segment_sizes = array<i32: 0, 4, 1, 0>} : () -> (i32, i32, i32, i32, i32)
"test.consumer"(%results#0, %results#1, %results#2, %results#3, %results#4) : (i32, i32, i32, i32, i32) -> ()
}

Expand Down
16 changes: 8 additions & 8 deletions mlir/test/Target/LLVMIR/openmp-llvm.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ llvm.func @wsloop_simple(%arg0: !llvm.ptr<f32>) {
llvm.store %3, %4 : !llvm.ptr<f32>
omp.yield
// CHECK: call void @__kmpc_for_static_fini(ptr @[[$wsloop_loc_struct]],
}) {operand_segment_sizes = dense<[1, 1, 1, 0, 0, 0, 0]> : vector<7xi32>} : (i64, i64, i64) -> ()
}) {operand_segment_sizes = array<i32: 1, 1, 1, 0, 0, 0, 0>} : (i64, i64, i64) -> ()
omp.terminator
}
llvm.return
Expand All @@ -399,7 +399,7 @@ llvm.func @wsloop_inclusive_1(%arg0: !llvm.ptr<f32>) {
%4 = llvm.getelementptr %arg0[%arg1] : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
llvm.store %3, %4 : !llvm.ptr<f32>
omp.yield
}) {operand_segment_sizes = dense<[1, 1, 1, 0, 0, 0, 0]> : vector<7xi32>} : (i64, i64, i64) -> ()
}) {operand_segment_sizes = array<i32: 1, 1, 1, 0, 0, 0, 0>} : (i64, i64, i64) -> ()
llvm.return
}

Expand All @@ -417,7 +417,7 @@ llvm.func @wsloop_inclusive_2(%arg0: !llvm.ptr<f32>) {
%4 = llvm.getelementptr %arg0[%arg1] : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
llvm.store %3, %4 : !llvm.ptr<f32>
omp.yield
}) {inclusive, operand_segment_sizes = dense<[1, 1, 1, 0, 0, 0, 0]> : vector<7xi32>} : (i64, i64, i64) -> ()
}) {inclusive, operand_segment_sizes = array<i32: 1, 1, 1, 0, 0, 0, 0>} : (i64, i64, i64) -> ()
llvm.return
}

Expand Down Expand Up @@ -697,8 +697,8 @@ llvm.func @simdloop_simple(%lb : i64, %ub : i64, %step : i64, %arg0: !llvm.ptr<f
%4 = llvm.getelementptr %arg0[%iv] : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
llvm.store %3, %4 : !llvm.ptr<f32>
omp.yield
}) {operand_segment_sizes = dense<[1,1,1,0]> : vector<4xi32>} :
(i64, i64, i64) -> ()
}) {operand_segment_sizes = array<i32: 1,1,1,0>} :
(i64, i64, i64) -> ()

llvm.return
}
Expand All @@ -720,7 +720,7 @@ llvm.func @simdloop_simple_multiple(%lb1 : i64, %ub1 : i64, %step1 : i64, %lb2 :
llvm.store %3, %4 : !llvm.ptr<f32>
llvm.store %3, %5 : !llvm.ptr<f32>
omp.yield
}
}
llvm.return
}
// CHECK: llvm.loop.parallel_accesses
Expand Down Expand Up @@ -753,9 +753,9 @@ llvm.func @simdloop_simple_multiple_simdlen(%lb1 : i64, %ub1 : i64, %step1 : i64
// CHECK-LABEL: @simdloop_if
llvm.func @simdloop_if(%arg0: !llvm.ptr<i32> {fir.bindc_name = "n"}, %arg1: !llvm.ptr<i32> {fir.bindc_name = "threshold"}) {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>} : (i64) -> !llvm.ptr<i32>
%1 = llvm.alloca %0 x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = array<i32: 0, 0>} : (i64) -> !llvm.ptr<i32>
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>, uniq_name = "_QFtest_simdEi"} : (i64) -> !llvm.ptr<i32>
%3 = llvm.alloca %2 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array<i32: 0, 0>, uniq_name = "_QFtest_simdEi"} : (i64) -> !llvm.ptr<i32>
%4 = llvm.mlir.constant(0 : i32) : i32
%5 = llvm.load %arg0 : !llvm.ptr<i32>
%6 = llvm.mlir.constant(1 : i32) : i32
Expand Down
2 changes: 1 addition & 1 deletion mlir/test/Transforms/canonicalize-block-merge.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ func.func @nomerge(%arg0: i32, %i: i32) {
func.func @mismatch_dominance() -> i32 {
// CHECK: %[[RES:.*]] = "test.producing_br"()
%0 = "test.producing_br"()[^bb1, ^bb2] {
operand_segment_sizes = dense<0> : vector<2 x i32>
operand_segment_sizes = array<i32: 0, 0>
} : () -> i32

^bb1:
Expand Down
3 changes: 1 addition & 2 deletions mlir/test/Transforms/sccp.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func.func @simple_produced_operand() -> (i32, i32) {
// CHECK: %[[ONE:.*]] = arith.constant 1
%1 = arith.constant 1 : i32
"test.internal_br"(%1) [^bb1, ^bb2] {
operand_segment_sizes = dense<[0, 1]> : vector<2 x i32>
operand_segment_sizes = array<i32: 0, 1>
} : (i32) -> ()

^bb1:
Expand All @@ -231,4 +231,3 @@ func.func @inplace_fold(%arg: i1) -> (i32) {
^b:
return %1 : i32
}

6 changes: 3 additions & 3 deletions mlir/test/lib/Dialect/Test/TestOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -716,14 +716,14 @@ def AttrSizedOperandOp : TEST_Op<"attr_sized_operands",
Variadic<I32>:$b,
I32:$c,
Variadic<I32>:$d,
I32ElementsAttr:$operand_segment_sizes
DenseI32ArrayAttr:$operand_segment_sizes
);
}

def AttrSizedResultOp : TEST_Op<"attr_sized_results",
[AttrSizedResultSegments]> {
let arguments = (ins
I32ElementsAttr:$result_segment_sizes
DenseI32ArrayAttr:$result_segment_sizes
);
let results = (outs
Variadic<I32>:$a,
Expand Down Expand Up @@ -2056,7 +2056,7 @@ def FormatVariadicOfVariadicOperand
: TEST_Op<"format_variadic_of_variadic_operand"> {
let arguments = (ins
VariadicOfVariadic<I64, "operand_segments">:$operand,
I32ElementsAttr:$operand_segments
DenseI32ArrayAttr:$operand_segments
);
let assemblyFormat = [{ $operand `:` type($operand) attr-dict}];
}
Expand Down
10 changes: 3 additions & 7 deletions mlir/test/python/dialects/linalg/ops.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
# RUN: %PYTHON %s | FileCheck %s

from mlir.ir import *
from mlir.dialects import arith
from mlir.dialects import builtin
from mlir.dialects import func
from mlir.dialects import linalg

from mlir.dialects import arith, builtin, func, linalg
from mlir.dialects.linalg.opdsl.lang import *
from mlir.ir import *


def run(f):
Expand Down Expand Up @@ -138,7 +134,7 @@ def named_form(lhs, rhs):
# CHECK-NEXT: arith.addf{{.*}} (f32, f32) -> f32
# CHECK-NEXT: linalg.yield{{.*}} (f32) -> ()
# CHECK-NEXT: cast = #linalg.type_fn<cast_signed>
# CHECK-SAME: operand_segment_sizes = dense<[2, 1]> : vector<2xi32>
# CHECK-SAME: operand_segment_sizes = array<i32: 2, 1>
# CHECK-SAME: (tensor<4x16xf32>, tensor<16x8xf32>, tensor<4x8xf32>) -> tensor<4x8xf32>
return linalg.matmul(lhs, rhs, outs=[init_result.result])

Expand Down
6 changes: 4 additions & 2 deletions mlir/test/python/dialects/ods_helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# RUN: %PYTHON %s | FileCheck %s

import gc

from mlir.ir import *


def run(f):
print("\nTEST:", f.__name__)
f()
Expand Down Expand Up @@ -125,8 +127,8 @@ class TestOp(OpView):
# CHECK: %[[V2:.+]] = "custom.value"
# CHECK: %[[V3:.+]] = "custom.value"
# CHECK: "custom.test_op"(%[[V0]], %[[V1]], %[[V2]], %[[V3]])
# CHECK-SAME: operand_segment_sizes = dense<[1, 2, 1]> : vector<3xi32>
# CHECK-SAME: result_segment_sizes = dense<[2, 1, 1]> : vector<3xi32>
# CHECK-SAME: operand_segment_sizes = array<i32: 1, 2, 1>
# CHECK-SAME: result_segment_sizes = array<i32: 2, 1, 1>>]
# CHECK-SAME: : (i32, i32, i32, i32) -> (i8, i16, i32, i64)
op = TestOp.build_generic(
results=[[t0, t1], t2, t3],
Expand Down
30 changes: 12 additions & 18 deletions mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,27 +94,23 @@ static const char *const sameVariadicSizeValueRangeCalcCode = R"(
/// the op has an attribute specifying the size of each operand/result segment
/// (variadic or not).
static const char *const attrSizedSegmentValueRangeCalcCode = R"(
const uint32_t *sizeAttrValueIt = &*sizeAttr.value_begin<uint32_t>();
if (sizeAttr.isSplat())
return {*sizeAttrValueIt * index, *sizeAttrValueIt};

unsigned start = 0;
for (unsigned i = 0; i < index; ++i)
start += sizeAttrValueIt[i];
return {start, sizeAttrValueIt[index]};
start += sizeAttr[i];
return {start, sizeAttr[index]};
)";
/// The code snippet to initialize the sizes for the value range calculation.
///
/// {0}: The code to get the attribute.
static const char *const adapterSegmentSizeAttrInitCode = R"(
assert(odsAttrs && "missing segment size attribute for op");
auto sizeAttr = {0}.cast<::mlir::DenseIntElementsAttr>();
auto sizeAttr = {0}.cast<::mlir::DenseI32ArrayAttr>();
)";
/// The code snippet to initialize the sizes for the value range calculation.
///
/// {0}: The code to get the attribute.
static const char *const opSegmentSizeAttrInitCode = R"(
auto sizeAttr = {0}.cast<::mlir::DenseIntElementsAttr>();
auto sizeAttr = {0}.cast<::mlir::DenseI32ArrayAttr>();
)";

/// The logic to calculate the actual value range for a declared operand
Expand All @@ -124,13 +120,12 @@ static const char *const opSegmentSizeAttrInitCode = R"(
/// {1}: The index of the main operand.
static const char *const variadicOfVariadicAdaptorCalcCode = R"(
auto tblgenTmpOperands = getODSOperands({1});
auto sizeAttrValues = {0}().getValues<uint32_t>();
auto sizeAttrIt = sizeAttrValues.begin();
auto sizes = {0}();

::llvm::SmallVector<::mlir::ValueRange> tblgenTmpOperandGroups;
for (int i = 0, e = ::llvm::size(sizeAttrValues); i < e; ++i, ++sizeAttrIt) {{
tblgenTmpOperandGroups.push_back(tblgenTmpOperands.take_front(*sizeAttrIt));
tblgenTmpOperands = tblgenTmpOperands.drop_front(*sizeAttrIt);
for (int i = 0, e = sizes.size(); i < e; ++i) {{
tblgenTmpOperandGroups.push_back(tblgenTmpOperands.take_front(sizes[i]));
tblgenTmpOperands = tblgenTmpOperands.drop_front(sizes[i]);
}
return tblgenTmpOperandGroups;
)";
Expand Down Expand Up @@ -608,9 +603,8 @@ static void genNativeTraitAttrVerifier(MethodBody &body,
// {3}: Emit error prefix.
const char *const checkAttrSizedValueSegmentsCode = R"(
{
auto sizeAttr = tblgen_{0}.cast<::mlir::DenseIntElementsAttr>();
auto numElements =
sizeAttr.getType().cast<::mlir::ShapedType>().getNumElements();
auto sizeAttr = tblgen_{0}.cast<::mlir::DenseI32ArrayAttr>();
auto numElements = sizeAttr.asArrayRef().size();
if (numElements != {1})
return {3}"'{0}' attribute for specifying {2} segments must have {1} "
"elements, but got ") << numElements;
Expand Down Expand Up @@ -2056,7 +2050,7 @@ void OpEmitter::genCodeForAddingArgAndRegionForBuilder(
<< op.getGetterName(
operand.constraint.getVariadicOfVariadicSegmentSizeAttr())
<< "AttrName(" << builderOpState << ".name), " << odsBuilder
<< ".getI32TensorAttr(rangeSegments));"
<< ".getDenseI32ArrayAttr(rangeSegments));"
<< " }\n";
continue;
}
Expand All @@ -2071,7 +2065,7 @@ void OpEmitter::genCodeForAddingArgAndRegionForBuilder(
std::string sizes = op.getGetterName(operandSegmentAttrName);
body << " " << builderOpState << ".addAttribute(" << sizes << "AttrName("
<< builderOpState << ".name), "
<< "odsBuilder.getI32VectorAttr({";
<< "odsBuilder.getDenseI32ArrayAttr({";
interleaveComma(llvm::seq<int>(0, op.getNumOperands()), body, [&](int i) {
const NamedTypeConstraint &operand = op.getOperand(i);
if (!operand.isVariableLength()) {
Expand Down
6 changes: 3 additions & 3 deletions mlir/tools/mlir-tblgen/OpFormatGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1558,7 +1558,7 @@ void OperationFormat::genParserVariadicSegmentResolution(Operator &op,
if (!allOperands) {
if (op.getTrait("::mlir::OpTrait::AttrSizedOperandSegments")) {
body << " result.addAttribute(\"operand_segment_sizes\", "
<< "parser.getBuilder().getI32VectorAttr({";
<< "parser.getBuilder().getDenseI32ArrayAttr({";
auto interleaveFn = [&](const NamedTypeConstraint &operand) {
// If the operand is variadic emit the parsed size.
if (operand.isVariableLength())
Expand All @@ -1574,7 +1574,7 @@ void OperationFormat::genParserVariadicSegmentResolution(Operator &op,
continue;
body << llvm::formatv(
" result.addAttribute(\"{0}\", "
"parser.getBuilder().getI32TensorAttr({1}OperandGroupSizes));\n",
"parser.getBuilder().getDenseI32ArrayAttr({1}OperandGroupSizes));\n",
operand.constraint.getVariadicOfVariadicSegmentSizeAttr(),
operand.name);
}
Expand All @@ -1583,7 +1583,7 @@ void OperationFormat::genParserVariadicSegmentResolution(Operator &op,
if (!allResultTypes &&
op.getTrait("::mlir::OpTrait::AttrSizedResultSegments")) {
body << " result.addAttribute(\"result_segment_sizes\", "
<< "parser.getBuilder().getI32VectorAttr({";
<< "parser.getBuilder().getDenseI32ArrayAttr({";
auto interleaveFn = [&](const NamedTypeConstraint &result) {
// If the result is variadic emit the parsed size.
if (result.isVariableLength())
Expand Down