diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -417,7 +417,7 @@ let results = (outs AnyType:$intype); let assemblyFormat = "type($intype) attr-dict"; - + // Note: we allow `undef : ref` since it is a possible from transformations. let hasVerifier = 0; } @@ -538,9 +538,9 @@ } } $_state.addAttribute(getOperandSegmentSizeAttr(), - $_builder.getI32VectorAttr({1, 0, sumArgs})); + $_builder.getDenseI32ArrayAttr({1, 0, sumArgs})); $_state.addAttribute(getTargetOffsetAttr(), - $_builder.getI32VectorAttr(argOffs)); + $_builder.getDenseI32ArrayAttr(argOffs)); $_state.addAttributes(attributes); }] >]; diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -113,7 +113,7 @@ builder.create(loc); op->setAttr(Op::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr(operandSegments)); + builder.getDenseI32ArrayAttr(operandSegments)); // Place the insertion point to the start of the first block. builder.setInsertionPointToStart(&block); @@ -129,7 +129,7 @@ llvm::ArrayRef argTy; Op op = builder.create(loc, argTy, operands); op->setAttr(Op::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr(operandSegments)); + builder.getDenseI32ArrayAttr(operandSegments)); return op; } diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -126,8 +126,9 @@ parser.emitError(parser.getNameLoc(), "invalid allocate type: ") << intype; return mlir::failure(); } - result.addAttribute("operand_segment_sizes", - builder.getI32VectorAttr({typeparamsSize, shapeSize})); + result.addAttribute( + "operand_segment_sizes", + builder.getDenseI32ArrayAttr({typeparamsSize, shapeSize})); if (parser.parseOptionalAttrDict(result.attributes) || parser.addTypeToList(restype, result.types)) return mlir::failure(); @@ -2431,8 +2432,8 @@ sumArgs += argSize; } result.addAttribute(operandSegmentAttr, - bld.getI32VectorAttr({1, 0, sumArgs})); - result.addAttribute(getTargetOffsetAttr(), bld.getI32VectorAttr(argOffs)); + bld.getDenseI32ArrayAttr({1, 0, sumArgs})); + result.addAttribute(getTargetOffsetAttr(), bld.getDenseI32ArrayAttr(argOffs)); return mlir::success(); } @@ -2480,13 +2481,12 @@ } template -static A getSubOperands(unsigned pos, A allArgs, - mlir::DenseIntElementsAttr ranges, +static A getSubOperands(unsigned pos, A allArgs, mlir::DenseI32ArrayAttr ranges, AdditionalArgs &&...additionalArgs) { unsigned start = 0; for (unsigned i = 0; i < pos; ++i) - start += (*(ranges.begin() + i)).getZExtValue(); - return allArgs.slice(start, (*(ranges.begin() + pos)).getZExtValue(), + start += ranges[i]; + return allArgs.slice(start, ranges[pos], std::forward(additionalArgs)...); } @@ -2498,14 +2498,10 @@ *owner->getAttrDictionary().getNamed(offsetAttr); return getSubOperands( pos, operands, - targetOffsetAttr.getValue().cast(), + targetOffsetAttr.getValue().cast(), mlir::MutableOperandRange::OperandSegment(pos, targetOffsetAttr)); } -static unsigned denseElementsSize(mlir::DenseIntElementsAttr attr) { - return attr.getNumElements(); -} - llvm::Optional fir::SelectOp::getCompareOperands(unsigned) { return {}; } @@ -2524,8 +2520,8 @@ fir::SelectOp::getSuccessorOperands(llvm::ArrayRef operands, unsigned oper) { auto a = - (*this)->getAttrOfType(getTargetOffsetAttr()); - auto segments = (*this)->getAttrOfType( + (*this)->getAttrOfType(getTargetOffsetAttr()); + auto segments = (*this)->getAttrOfType( getOperandSegmentSizeAttr()); return {getSubOperands(oper, getSubOperands(2, operands, segments), a)}; } @@ -2533,15 +2529,16 @@ llvm::Optional fir::SelectOp::getSuccessorOperands(mlir::ValueRange operands, unsigned oper) { auto a = - (*this)->getAttrOfType(getTargetOffsetAttr()); - auto segments = (*this)->getAttrOfType( + (*this)->getAttrOfType(getTargetOffsetAttr()); + auto segments = (*this)->getAttrOfType( getOperandSegmentSizeAttr()); return {getSubOperands(oper, getSubOperands(2, operands, segments), a)}; } unsigned fir::SelectOp::targetOffsetSize() { - return denseElementsSize((*this)->getAttrOfType( - getTargetOffsetAttr())); + return (*this) + ->getAttrOfType(getTargetOffsetAttr()) + .size(); } //===----------------------------------------------------------------------===// @@ -2550,17 +2547,17 @@ llvm::Optional fir::SelectCaseOp::getCompareOperands(unsigned cond) { - auto a = (*this)->getAttrOfType( - getCompareOffsetAttr()); + auto a = + (*this)->getAttrOfType(getCompareOffsetAttr()); return {getSubOperands(cond, getCompareArgs(), a)}; } llvm::Optional> fir::SelectCaseOp::getCompareOperands(llvm::ArrayRef operands, unsigned cond) { - auto a = (*this)->getAttrOfType( - getCompareOffsetAttr()); - auto segments = (*this)->getAttrOfType( + auto a = + (*this)->getAttrOfType(getCompareOffsetAttr()); + auto segments = (*this)->getAttrOfType( getOperandSegmentSizeAttr()); return {getSubOperands(cond, getSubOperands(1, operands, segments), a)}; } @@ -2568,9 +2565,9 @@ llvm::Optional fir::SelectCaseOp::getCompareOperands(mlir::ValueRange operands, unsigned cond) { - auto a = (*this)->getAttrOfType( - getCompareOffsetAttr()); - auto segments = (*this)->getAttrOfType( + auto a = + (*this)->getAttrOfType(getCompareOffsetAttr()); + auto segments = (*this)->getAttrOfType( getOperandSegmentSizeAttr()); return {getSubOperands(cond, getSubOperands(1, operands, segments), a)}; } @@ -2584,8 +2581,8 @@ fir::SelectCaseOp::getSuccessorOperands(llvm::ArrayRef operands, unsigned oper) { auto a = - (*this)->getAttrOfType(getTargetOffsetAttr()); - auto segments = (*this)->getAttrOfType( + (*this)->getAttrOfType(getTargetOffsetAttr()); + auto segments = (*this)->getAttrOfType( getOperandSegmentSizeAttr()); return {getSubOperands(oper, getSubOperands(2, operands, segments), a)}; } @@ -2594,8 +2591,8 @@ fir::SelectCaseOp::getSuccessorOperands(mlir::ValueRange operands, unsigned oper) { auto a = - (*this)->getAttrOfType(getTargetOffsetAttr()); - auto segments = (*this)->getAttrOfType( + (*this)->getAttrOfType(getTargetOffsetAttr()); + auto segments = (*this)->getAttrOfType( getOperandSegmentSizeAttr()); return {getSubOperands(oper, getSubOperands(2, operands, segments), a)}; } @@ -2668,9 +2665,11 @@ } auto &bld = parser.getBuilder(); result.addAttribute(fir::SelectCaseOp::getOperandSegmentSizeAttr(), - bld.getI32VectorAttr({1, offSize, toffSize})); - result.addAttribute(getCompareOffsetAttr(), bld.getI32VectorAttr(argOffs)); - result.addAttribute(getTargetOffsetAttr(), bld.getI32VectorAttr(targOffs)); + bld.getDenseI32ArrayAttr({1, offSize, toffSize})); + result.addAttribute(getCompareOffsetAttr(), + bld.getDenseI32ArrayAttr(argOffs)); + result.addAttribute(getTargetOffsetAttr(), + bld.getDenseI32ArrayAttr(targOffs)); return mlir::success(); } @@ -2703,13 +2702,15 @@ } unsigned fir::SelectCaseOp::compareOffsetSize() { - return denseElementsSize((*this)->getAttrOfType( - getCompareOffsetAttr())); + return (*this) + ->getAttrOfType(getCompareOffsetAttr()) + .size(); } unsigned fir::SelectCaseOp::targetOffsetSize() { - return denseElementsSize((*this)->getAttrOfType( - getTargetOffsetAttr())); + return (*this) + ->getAttrOfType(getTargetOffsetAttr()) + .size(); } void fir::SelectCaseOp::build(mlir::OpBuilder &builder, @@ -2738,7 +2739,7 @@ for (auto ops : cmpOperands) result.addOperands(ops); result.addAttribute(getCompareOffsetAttr(), - builder.getI32VectorAttr(operOffs)); + builder.getDenseI32ArrayAttr(operOffs)); const auto count = destinations.size(); for (auto d : destinations) result.addSuccessors(d); @@ -2756,8 +2757,9 @@ } } result.addAttribute(getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({1, operSize, sumArgs})); - result.addAttribute(getTargetOffsetAttr(), builder.getI32VectorAttr(argOffs)); + builder.getDenseI32ArrayAttr({1, operSize, sumArgs})); + result.addAttribute(getTargetOffsetAttr(), + builder.getDenseI32ArrayAttr(argOffs)); result.addAttributes(attributes); } @@ -2854,8 +2856,8 @@ fir::SelectRankOp::getSuccessorOperands(llvm::ArrayRef operands, unsigned oper) { auto a = - (*this)->getAttrOfType(getTargetOffsetAttr()); - auto segments = (*this)->getAttrOfType( + (*this)->getAttrOfType(getTargetOffsetAttr()); + auto segments = (*this)->getAttrOfType( getOperandSegmentSizeAttr()); return {getSubOperands(oper, getSubOperands(2, operands, segments), a)}; } @@ -2864,15 +2866,16 @@ fir::SelectRankOp::getSuccessorOperands(mlir::ValueRange operands, unsigned oper) { auto a = - (*this)->getAttrOfType(getTargetOffsetAttr()); - auto segments = (*this)->getAttrOfType( + (*this)->getAttrOfType(getTargetOffsetAttr()); + auto segments = (*this)->getAttrOfType( getOperandSegmentSizeAttr()); return {getSubOperands(oper, getSubOperands(2, operands, segments), a)}; } unsigned fir::SelectRankOp::targetOffsetSize() { - return denseElementsSize((*this)->getAttrOfType( - getTargetOffsetAttr())); + return (*this) + ->getAttrOfType(getTargetOffsetAttr()) + .size(); } //===----------------------------------------------------------------------===// @@ -2898,8 +2901,8 @@ fir::SelectTypeOp::getSuccessorOperands(llvm::ArrayRef operands, unsigned oper) { auto a = - (*this)->getAttrOfType(getTargetOffsetAttr()); - auto segments = (*this)->getAttrOfType( + (*this)->getAttrOfType(getTargetOffsetAttr()); + auto segments = (*this)->getAttrOfType( getOperandSegmentSizeAttr()); return {getSubOperands(oper, getSubOperands(2, operands, segments), a)}; } @@ -2944,14 +2947,15 @@ offSize += argSize; } result.addAttribute(fir::SelectTypeOp::getOperandSegmentSizeAttr(), - bld.getI32VectorAttr({1, 0, offSize})); - result.addAttribute(getTargetOffsetAttr(), bld.getI32VectorAttr(argOffs)); + bld.getDenseI32ArrayAttr({1, 0, offSize})); + result.addAttribute(getTargetOffsetAttr(), bld.getDenseI32ArrayAttr(argOffs)); return mlir::success(); } unsigned fir::SelectTypeOp::targetOffsetSize() { - return denseElementsSize((*this)->getAttrOfType( - getTargetOffsetAttr())); + return (*this) + ->getAttrOfType(getTargetOffsetAttr()) + .size(); } void fir::SelectTypeOp::print(mlir::OpAsmPrinter &p) { @@ -3021,8 +3025,9 @@ } } result.addAttribute(getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({1, 0, sumArgs})); - result.addAttribute(getTargetOffsetAttr(), builder.getI32VectorAttr(argOffs)); + builder.getDenseI32ArrayAttr({1, 0, sumArgs})); + result.addAttribute(getTargetOffsetAttr(), + builder.getDenseI32ArrayAttr(argOffs)); result.addAttributes(attributes); } diff --git a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir --- a/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir +++ b/flang/test/Fir/convert-to-llvm-openmp-and-fir.fir @@ -28,7 +28,7 @@ // CHECK: %[[ONE_2:.*]] = llvm.mlir.constant(1 : i32) : i32 // CHECK: omp.parallel { // CHECK: %[[ONE_3:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[I_VAR:.*]] = llvm.alloca %[[ONE_3]] x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>, pinned} : (i64) -> !llvm.ptr +// CHECK: %[[I_VAR:.*]] = llvm.alloca %[[ONE_3]] x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = array, pinned} : (i64) -> !llvm.ptr // CHECK: %[[N:.*]] = llvm.load %[[N_REF]] : !llvm.ptr // CHECK: omp.wsloop nowait // CHECK-SAME: for (%[[I:.*]]) : i32 = (%[[ONE_2]]) to (%[[N]]) inclusive step (%[[ONE_2]]) { @@ -201,7 +201,7 @@ // CHECK: %[[ONE_2:.*]] = llvm.mlir.constant(1 : i32) : i32 // CHECK: omp.parallel { // CHECK: %[[ONE_3:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[I_VAR:.*]] = llvm.alloca %[[ONE_3]] x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>, pinned} : (i64) -> !llvm.ptr +// CHECK: %[[I_VAR:.*]] = llvm.alloca %[[ONE_3]] x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = array, pinned} : (i64) -> !llvm.ptr // CHECK: %[[N:.*]] = llvm.load %[[N_REF]] : !llvm.ptr // CHECK: omp.simdloop // CHECK-SAME: (%[[I:.*]]) : i32 = (%[[ONE_2]]) to (%[[N]]) step (%[[ONE_2]]) { diff --git a/flang/test/Fir/convert-to-llvm.fir b/flang/test/Fir/convert-to-llvm.fir --- a/flang/test/Fir/convert-to-llvm.fir +++ b/flang/test/Fir/convert-to-llvm.fir @@ -1701,7 +1701,7 @@ // CHECK-LABEL: llvm.func @no_reassoc( // CHECK-SAME: %[[ARG0:.*]]: !llvm.ptr) { // CHECK: %[[C1:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[ALLOC:.*]] = llvm.alloca %[[C1]] x i32 {in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>} : (i64) -> !llvm.ptr +// CHECK: %[[ALLOC:.*]] = llvm.alloca %[[C1]] x i32 {in_type = i32, operand_segment_sizes = array} : (i64) -> !llvm.ptr // CHECK: %[[LOAD:.*]] = llvm.load %[[ARG0]] : !llvm.ptr // CHECK: llvm.store %[[LOAD]], %[[ALLOC]] : !llvm.ptr // CHECK: llvm.return @@ -1821,7 +1821,7 @@ // CHECK: %[[C1_0:.*]] = llvm.mlir.constant(1 : i64) : i64 // CHECK: %[[ARR_SIZE_TMP1:.*]] = llvm.mul %[[C1_0]], %[[N1]] : i64 // CHECK: %[[ARR_SIZE:.*]] = llvm.mul %[[ARR_SIZE_TMP1]], %[[N2]] : i64 -// CHECK: %[[ARR:.*]] = llvm.alloca %[[ARR_SIZE]] x f64 {bindc_name = "arr", in_type = !fir.array, operand_segment_sizes = dense<[0, 2]> : vector<2xi32>, uniq_name = "_QFsbEarr"} : (i64) -> !llvm.ptr +// CHECK: %[[ARR:.*]] = llvm.alloca %[[ARR_SIZE]] x f64 {bindc_name = "arr", in_type = !fir.array, operand_segment_sizes = array, uniq_name = "_QFsbEarr"} : (i64) -> !llvm.ptr // CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<2 x array<3 x i64>>)> // CHECK: %[[ELEM_LEN:.*]] = llvm.mlir.constant(8 : i32) : i32 // CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(28 : i32) : i32 @@ -1898,9 +1898,9 @@ // CHECK: %[[C10:.*]] = llvm.mlir.constant(10 : i64) : i64 // CHECK: %[[C2:.*]] = llvm.mlir.constant(2 : i64) : i64 // CHECK: %[[ALLOCA_SIZE_V:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[V:.*]] = llvm.alloca %[[ALLOCA_SIZE_V]] x i32 {bindc_name = "v", in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>, uniq_name = "_QFtest_dt_sliceEv"} : (i64) -> !llvm.ptr +// CHECK: %[[V:.*]] = llvm.alloca %[[ALLOCA_SIZE_V]] x i32 {bindc_name = "v", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFtest_dt_sliceEv"} : (i64) -> !llvm.ptr // CHECK: %[[ALLOCA_SIZE_X:.*]] = llvm.mlir.constant(1 : i64) : i64 -// CHECK: %[[X:.*]] = llvm.alloca %[[ALLOCA_SIZE_X]] x !llvm.array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>> {bindc_name = "x", in_type = !fir.array<20x!fir.type<_QFtest_dt_sliceTt{i:i32,j:i32}>>, operand_segment_sizes = dense<0> : vector<2xi32>, uniq_name = "_QFtest_dt_sliceEx"} : (i64) -> !llvm.ptr>> +// CHECK: %[[X:.*]] = llvm.alloca %[[ALLOCA_SIZE_X]] x !llvm.array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>> {bindc_name = "x", in_type = !fir.array<20x!fir.type<_QFtest_dt_sliceTt{i:i32,j:i32}>>, operand_segment_sizes = array, uniq_name = "_QFtest_dt_sliceEx"} : (i64) -> !llvm.ptr>> // CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, i{{.*}}, array<1 x array<3 x i64>>)> // CHECK: %[[ELEM_LEN:.*]] = llvm.mlir.constant(4 : i32) : i32 // CHECK: %[[TYPE_CODE:.*]] = llvm.mlir.constant(9 : i32) : i32 diff --git a/mlir/docs/PatternRewriter.md b/mlir/docs/PatternRewriter.md --- a/mlir/docs/PatternRewriter.md +++ b/mlir/docs/PatternRewriter.md @@ -357,7 +357,7 @@ ``` //===-------------------------------------------===// Processing operation : 'cf.cond_br'(0x60f000001120) { - "cf.cond_br"(%arg0)[^bb2, ^bb2] {operand_segment_sizes = dense<[1, 0, 0]> : vector<3xi32>} : (i1) -> () + "cf.cond_br"(%arg0)[^bb2, ^bb2] {operand_segment_sizes = array} : (i1) -> () * Pattern SimplifyConstCondBranchPred : 'cf.cond_br -> ()' { } -> failure : pattern failed to match diff --git a/mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.td b/mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.td --- a/mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.td +++ b/mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.td @@ -254,7 +254,7 @@ Variadic:$defaultOperands, VariadicOfVariadic:$caseOperands, OptionalAttr:$case_values, - I32ElementsAttr:$case_operand_segments + DenseI32ArrayAttr:$case_operand_segments ); let successors = (successor AnySuccessor:$defaultDestination, diff --git a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -915,7 +915,7 @@ Variadic:$defaultOperands, VariadicOfVariadic:$caseOperands, OptionalAttr:$case_values, - ElementsAttr:$case_operand_segments, + DenseI32ArrayAttr:$case_operand_segments, OptionalAttr:$branch_weights ); let successors = (successor diff --git a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td --- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td +++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td @@ -86,7 +86,7 @@ $_state.addOperands(dynamicSizes); $_state.addOperands(symbolOperands); $_state.addAttribute(getOperandSegmentSizeAttr(), - $_builder.getI32VectorAttr({ + $_builder.getDenseI32ArrayAttr({ static_cast(dynamicSizes.size()), static_cast(symbolOperands.size())})); if (alignment) diff --git a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td --- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td +++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td @@ -417,7 +417,7 @@ ```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} -> diff --git a/mlir/include/mlir/IR/ValueRange.h b/mlir/include/mlir/IR/ValueRange.h --- a/mlir/include/mlir/IR/ValueRange.h +++ b/mlir/include/mlir/IR/ValueRange.h @@ -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" @@ -22,7 +23,6 @@ class ValueRange; template class ValueTypeRange; -class ElementsAttr; class TypeRangeRange; template class ValueTypeIterator; @@ -54,7 +54,7 @@ /// 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. @@ -114,8 +114,8 @@ 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; /// Construct a new mutable range from the given operand, operand start index, diff --git a/mlir/lib/Dialect/Async/IR/Async.cpp b/mlir/lib/Dialect/Async/IR/Async.cpp --- a/mlir/lib/Dialect/Async/IR/Async.cpp +++ b/mlir/lib/Dialect/Async/IR/Async.cpp @@ -97,9 +97,8 @@ // 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 @@ -203,9 +202,8 @@ 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. diff --git a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp --- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp @@ -388,7 +388,7 @@ if (parser.resolveOperand(copyOperand, type, result.operands)) return failure(); result.addAttribute(AllocTensorOp::getOperandSegmentSizeAttr(), - parser.getBuilder().getI32VectorAttr( + parser.getBuilder().getDenseI32ArrayAttr( {static_cast(dynamicSizesOperands.size()), static_cast(copyKeyword.succeeded())})); return success(); diff --git a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -374,15 +374,15 @@ return; auto attrName = OpTrait::AttrSizedOperandSegments::getOperandSegmentSizeAttr(); - auto sizeAttr = op->template getAttrOfType(attrName); + auto sizeAttr = op->template getAttrOfType(attrName); // Async dependencies is the only variadic operand. if (!sizeAttr) return; - SmallVector sizes(sizeAttr.getValues()); + SmallVector sizes(sizeAttr.asArrayRef()); ++sizes.front(); - op->setAttr(attrName, Builder(op->getContext()).getI32VectorAttr(sizes)); + op->setAttr(attrName, Builder(op->getContext()).getDenseI32ArrayAttr(sizes)); } //===----------------------------------------------------------------------===// @@ -416,7 +416,7 @@ segmentSizes.front() = asyncDependencies.size(); segmentSizes.back() = dynamicSharedMemorySize ? 1 : 0; result.addAttribute(getOperandSegmentSizeAttr(), - builder.getI32VectorAttr(segmentSizes)); + builder.getDenseI32ArrayAttr(segmentSizes)); } KernelDim3 LaunchOp::getBlockIds() { @@ -636,7 +636,7 @@ segmentSizes.front() = asyncDependencies.size(); segmentSizes.back() = hasDynamicSharedMemorySize ? 1 : 0; result.addAttribute(LaunchOp::getOperandSegmentSizeAttr(), - parser.getBuilder().getI32VectorAttr(segmentSizes)); + parser.getBuilder().getDenseI32ArrayAttr(segmentSizes)); return success(); } @@ -709,7 +709,7 @@ segmentSizes[segmentSizes.size() - 2] = dynamicSharedMemorySize ? 1 : 0; segmentSizes.back() = static_cast(kernelOperands.size()); result.addAttribute(getOperandSegmentSizeAttr(), - builder.getI32VectorAttr(segmentSizes)); + builder.getDenseI32ArrayAttr(segmentSizes)); } StringAttr LaunchFuncOp::getKernelModuleName() { diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1048,11 +1048,11 @@ result.addOperands(normalOperands); result.addOperands(unwindOperands); - result.addAttribute( - InvokeOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({static_cast(operands.size()), - static_cast(normalOperands.size()), - static_cast(unwindOperands.size())})); + result.addAttribute(InvokeOp::getOperandSegmentSizeAttr(), + builder.getDenseI32ArrayAttr( + {static_cast(operands.size()), + static_cast(normalOperands.size()), + static_cast(unwindOperands.size())})); return success(); } diff --git a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp --- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp @@ -233,9 +233,9 @@ result.addTypes(resultType); result.addAttribute( MmaOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({static_cast(operandA.size()), - static_cast(operandB.size()), - static_cast(operandC.size())})); + builder.getDenseI32ArrayAttr({static_cast(operandA.size()), + static_cast(operandB.size()), + static_cast(operandC.size())})); } // := @@ -326,7 +326,7 @@ if (!namedAttributes.empty()) result.addAttributes(namedAttributes); result.addAttribute(MmaOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({ + builder.getDenseI32ArrayAttr({ static_cast(frags[0].regs.size()), static_cast(frags[1].regs.size()), static_cast(frags[2].regs.size()), diff --git a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -111,8 +111,8 @@ state.addAttributes(attributes); state.addAttribute( "operand_segment_sizes", - b.getI32VectorAttr({static_cast(inputs.size()), - static_cast(outputs.size())})); + b.getDenseI32ArrayAttr({static_cast(inputs.size()), + static_cast(outputs.size())})); // Create and fill the region of the structured operation. Region ®ion = *state.addRegion(); @@ -157,7 +157,7 @@ return failure(); result.addAttribute("operand_segment_sizes", - parser.getBuilder().getI32VectorAttr( + parser.getBuilder().getDenseI32ArrayAttr( {static_cast(inputsOperands.size()), static_cast(outputsOperands.size())})); return success(); diff --git a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp --- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp +++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp @@ -361,7 +361,7 @@ result.addAttribute( ParallelOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr( + builder.getDenseI32ArrayAttr( {static_cast(async.has_value() ? 1 : 0), static_cast(waitOperands.size()), static_cast(numGangs.has_value() ? 1 : 0), @@ -590,7 +590,7 @@ return failure(); result.addAttribute(LoopOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr( + builder.getDenseI32ArrayAttr( {static_cast(gangNum.has_value() ? 1 : 0), static_cast(gangStatic.has_value() ? 1 : 0), static_cast(worker.has_value() ? 1 : 0), diff --git a/mlir/lib/Dialect/SCF/IR/SCF.cpp b/mlir/lib/Dialect/SCF/IR/SCF.cpp --- a/mlir/lib/Dialect/SCF/IR/SCF.cpp +++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp @@ -2105,10 +2105,10 @@ result.addOperands(initVals); result.addAttribute( ParallelOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({static_cast(lowerBounds.size()), - static_cast(upperBounds.size()), - static_cast(steps.size()), - static_cast(initVals.size())})); + builder.getDenseI32ArrayAttr({static_cast(lowerBounds.size()), + static_cast(upperBounds.size()), + static_cast(steps.size()), + static_cast(initVals.size())})); result.addTypes(initVals.getTypes()); OpBuilder::InsertionGuard guard(builder); @@ -2258,10 +2258,10 @@ // Set `operand_segment_sizes` attribute. result.addAttribute( ParallelOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({static_cast(lower.size()), - static_cast(upper.size()), - static_cast(steps.size()), - static_cast(initVals.size())})); + builder.getDenseI32ArrayAttr({static_cast(lower.size()), + static_cast(upper.size()), + static_cast(steps.size()), + static_cast(initVals.size())})); // Parse attributes. if (parser.parseOptionalAttrDict(result.attributes) || diff --git a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp @@ -1579,10 +1579,10 @@ return failure(); result.addSuccessors(dest); result.addOperands(falseOperands); - result.addAttribute( - spirv::BranchConditionalOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({1, static_cast(trueOperands.size()), - static_cast(falseOperands.size())})); + result.addAttribute(spirv::BranchConditionalOp::getOperandSegmentSizeAttr(), + builder.getDenseI32ArrayAttr( + {1, static_cast(trueOperands.size()), + static_cast(falseOperands.size())})); return success(); } diff --git a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp --- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp @@ -3015,10 +3015,10 @@ if (parser.resolveOperand(maskInfo, maskType, result.operands)) return failure(); } - result.addAttribute( - TransferReadOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({1, static_cast(indexInfo.size()), 1, - static_cast(hasMask.succeeded())})); + result.addAttribute(TransferReadOp::getOperandSegmentSizeAttr(), + builder.getDenseI32ArrayAttr( + {1, static_cast(indexInfo.size()), 1, + static_cast(hasMask.succeeded())})); return parser.addTypeToList(vectorType, result.types); } @@ -3465,10 +3465,10 @@ if (parser.resolveOperand(maskInfo, maskType, result.operands)) return failure(); } - result.addAttribute( - TransferWriteOp::getOperandSegmentSizeAttr(), - builder.getI32VectorAttr({1, 1, static_cast(indexInfo.size()), - static_cast(hasMask.succeeded())})); + result.addAttribute(TransferWriteOp::getOperandSegmentSizeAttr(), + builder.getDenseI32ArrayAttr( + {1, 1, static_cast(indexInfo.size()), + static_cast(hasMask.succeeded())})); return failure(shapedType.isa() && parser.addTypeToList(shapedType, result.types)); } diff --git a/mlir/lib/IR/Operation.cpp b/mlir/lib/IR/Operation.cpp --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -987,26 +987,19 @@ StringRef attrName, StringRef valueGroupName, size_t expectedCount) { - auto sizeAttr = op->getAttrOfType(attrName); + auto sizeAttr = op->getAttrOfType(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(), [](const APInt &element) { - return !element.isNonNegative(); - })) + ArrayRef 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() diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp --- a/mlir/lib/IR/OperationSupport.cpp +++ b/mlir/lib/IR/OperationSupport.cpp @@ -377,7 +377,7 @@ return base->getOperandNumber(); } -OperandRangeRange OperandRange::split(ElementsAttr segmentSizes) const { +OperandRangeRange OperandRange::split(DenseI32ArrayAttr segmentSizes) const { return OperandRangeRange(*this, segmentSizes); } @@ -387,18 +387,18 @@ OperandRangeRange::OperandRangeRange(OperandRange operands, Attribute operandSegments) : OperandRangeRange(OwnerT(operands.getBase(), operandSegments), 0, - operandSegments.cast().size()) {} + operandSegments.cast().size()) {} OperandRange OperandRangeRange::join() const { const OwnerT &owner = getBase(); - auto sizeData = owner.second.cast().getValues(); + ArrayRef sizeData = owner.second.cast(); 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().getValues(); + ArrayRef sizeData = object.second.cast(); uint32_t startIndex = std::accumulate(sizeData.begin(), sizeData.begin() + index, 0); return OperandRange(object.first + startIndex, *(sizeData.begin() + index)); @@ -490,11 +490,11 @@ // Update any of the provided segment attributes. for (OperandSegment &segment : operandSegments) { - auto attr = segment.second.getValue().cast(); - SmallVector segments(attr.getValues()); + auto attr = segment.second.getValue().cast(); + SmallVector 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()); } } @@ -506,21 +506,20 @@ const MutableOperandRange &operands, NamedAttribute operandSegmentAttr) : MutableOperandRangeRange( OwnerT(operands, operandSegmentAttr), 0, - operandSegmentAttr.getValue().cast().size()) {} + operandSegmentAttr.getValue().cast().size()) {} MutableOperandRange MutableOperandRangeRange::join() const { return getBase().first; } MutableOperandRangeRange::operator OperandRangeRange() const { - return OperandRangeRange( - getBase().first, getBase().second.getValue().cast()); + return OperandRangeRange(getBase().first, getBase().second.getValue()); } MutableOperandRange MutableOperandRangeRange::dereference(const OwnerT &object, ptrdiff_t index) { - auto sizeData = - object.second.getValue().cast().getValues(); + ArrayRef sizeData = + object.second.getValue().cast(); uint32_t startIndex = std::accumulate(sizeData.begin(), sizeData.begin() + index, 0); return object.first.slice( diff --git a/mlir/lib/Rewrite/ByteCode.cpp b/mlir/lib/Rewrite/ByteCode.cpp --- a/mlir/lib/Rewrite/ByteCode.cpp +++ b/mlir/lib/Rewrite/ByteCode.cpp @@ -1713,11 +1713,11 @@ LLVM_DEBUG(llvm::dbgs() << " * Extracting values from `" << attrSizedSegments << "`\n"); - auto segmentAttr = op->getAttrOfType(attrSizedSegments); - if (!segmentAttr || segmentAttr.getNumElements() <= index) + auto segmentAttr = op->getAttrOfType(attrSizedSegments); + if (!segmentAttr || segmentAttr.asArrayRef().size() <= index) return nullptr; - auto segments = segmentAttr.getValues(); + ArrayRef segments = segmentAttr; unsigned startIndex = std::accumulate(segments.begin(), segments.begin() + index, 0); values = values.slice(startIndex, *std::next(segments.begin(), index)); diff --git a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -906,7 +906,7 @@ if (brInst->isConditional()) { state.addAttribute(LLVM::CondBrOp::getOperandSegmentSizeAttr(), - b.getI32VectorAttr(operandSegmentSizes)); + b.getDenseI32ArrayAttr(operandSegmentSizes)); } b.create(state); diff --git a/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir b/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir --- a/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir +++ b/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir @@ -73,13 +73,13 @@ 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} : (index, index, index, index, index, index) -> () omp.terminator } return diff --git a/mlir/test/Dialect/GPU/invalid.mlir b/mlir/test/Dialect/GPU/invalid.mlir --- a/mlir/test/Dialect/GPU/invalid.mlir +++ b/mlir/test/Dialect/GPU/invalid.mlir @@ -4,7 +4,7 @@ // 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} : (index, index, index, index, index) -> () return } @@ -16,7 +16,7 @@ ^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} : (index, index, index, index, index, index) -> () return } @@ -38,7 +38,7 @@ 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} : (index, index, index, index, index) -> () return } @@ -57,7 +57,7 @@ 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} : (index, index, index, index, index, index) -> () return } diff --git a/mlir/test/Dialect/Linalg/named-ops.mlir b/mlir/test/Dialect/Linalg/named-ops.mlir --- a/mlir/test/Dialect/Linalg/named-ops.mlir +++ b/mlir/test/Dialect/Linalg/named-ops.mlir @@ -742,7 +742,7 @@ %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, tensor, tensor) -> tensor + }) {dilations = dense<1> : tensor<2xi64>, linalg.memoized_indexing_maps = [#map0, #map1, #map2], operand_segment_sizes = array, strides = dense<2> : tensor<2xi64>} : (tensor, tensor, tensor) -> tensor return %0 : tensor } @@ -759,6 +759,6 @@ %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, tensor, tensor) -> tensor + }) {dilations = dense<1> : tensor<2xi64>, linalg.memoized_indexing_maps = [#map0, #map1, #map2], operand_segment_sizes = array, strides = dense<1> : tensor<2xi64>} : (tensor, tensor, tensor) -> tensor return %0 : tensor } diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir b/mlir/test/Dialect/OpenMP/invalid.mlir --- a/mlir/test/Dialect/OpenMP/invalid.mlir +++ b/mlir/test/Dialect/OpenMP/invalid.mlir @@ -197,8 +197,8 @@ "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} : + (index, index, i32) -> () return } @@ -985,7 +985,7 @@ // 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) -> () + }) {operand_segment_sizes = array} : (memref) -> () return } @@ -995,7 +995,7 @@ // 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) -> () + }) {operand_segment_sizes = array} : (memref) -> () return } @@ -1110,7 +1110,7 @@ // 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) -> () + }) {operand_segment_sizes = array} : (memref) -> () return } @@ -1302,7 +1302,7 @@ "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) -> () + }) {operand_segment_sizes = array} : (i32, i32, i32, i32, i32, i32, memref) -> () return } @@ -1315,7 +1315,7 @@ "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, !llvm.ptr) -> () + }) {operand_segment_sizes = array, reductions = [@add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr) -> () return } @@ -1328,7 +1328,7 @@ "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) -> () + }) {operand_segment_sizes = array, reductions = [@add_f32, @add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr) -> () return } @@ -1341,7 +1341,7 @@ "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, !llvm.ptr) -> () + }) {in_reductions = [@add_f32], operand_segment_sizes = array} : (i32, i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr) -> () return } @@ -1354,7 +1354,7 @@ "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) -> () + }) {in_reductions = [@add_f32, @add_f32], operand_segment_sizes = array} : (i32, i32, i32, i32, i32, i32, !llvm.ptr) -> () return } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -59,7 +59,7 @@ // CHECK: omp.parallel num_threads(%{{.*}} : i32) allocate(%{{.*}} : memref -> %{{.*}} : memref) "omp.parallel"(%num_threads, %data_var, %data_var) ({ omp.terminator - }) {operand_segment_sizes = dense<[0,1,1,1,0]> : vector<5xi32>} : (i32, memref, memref) -> () + }) {operand_segment_sizes = array} : (i32, memref, memref) -> () // CHECK: omp.barrier omp.barrier @@ -68,22 +68,22 @@ // CHECK: omp.parallel if(%{{.*}}) allocate(%{{.*}} : memref -> %{{.*}} : memref) "omp.parallel"(%if_cond, %data_var, %data_var) ({ omp.terminator - }) {operand_segment_sizes = dense<[1,0,1,1,0]> : vector<5xi32>} : (i1, memref, memref) -> () + }) {operand_segment_sizes = array} : (i1, memref, memref) -> () // 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} : (i1, i32) -> () omp.terminator - }) {operand_segment_sizes = dense<[1,1,1,1,0]> : vector<5xi32>, proc_bind_val = #omp} : (i1, i32, memref, memref) -> () + }) {operand_segment_sizes = array, proc_bind_val = #omp} : (i1, i32, memref, memref) -> () // test with multiple parameters for single variadic argument // CHECK: omp.parallel allocate(%{{.*}} : memref -> %{{.*}} : memref) "omp.parallel" (%data_var, %data_var) ({ omp.terminator - }) {operand_segment_sizes = dense<[0,0,1,1,0]> : vector<5xi32>} : (memref, memref) -> () + }) {operand_segment_sizes = array} : (memref, memref) -> () return } @@ -141,7 +141,7 @@ "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, ordered_val = 1} : (index, index, index) -> () // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(static) @@ -149,7 +149,7 @@ "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} : + }) {operand_segment_sizes = array, schedule_val = #omp} : (index, index, index, memref, i32) -> () // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref, %{{.*}} = %{{.*}} : memref) schedule(static) @@ -157,7 +157,7 @@ "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} : + }) {operand_segment_sizes = array, schedule_val = #omp} : (index, index, index, memref, memref, i32, i32) -> () // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(dynamic = %{{.*}}) ordered(2) @@ -165,7 +165,7 @@ "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, ordered_val = 2} : + }) {operand_segment_sizes = array, schedule_val = #omp, ordered_val = 2} : (index, index, index, memref, i32, i32) -> () // CHECK: omp.wsloop schedule(auto) nowait @@ -173,7 +173,7 @@ "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} : + }) {operand_segment_sizes = array, nowait, schedule_val = #omp} : (index, index, index) -> () return @@ -333,8 +333,8 @@ "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} : + (index, index, index) -> () return } @@ -383,7 +383,7 @@ "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} : ( i1, si32, i32 ) -> () // CHECK: omp.barrier omp.barrier @@ -1227,13 +1227,13 @@ "omp.sections" (%data_var1, %data_var1) ({ // CHECK: omp.terminator omp.terminator - }) {operand_segment_sizes = dense<[0,1,1]> : vector<3xi32>} : (memref, memref) -> () + }) {operand_segment_sizes = array} : (memref, memref) -> () // CHECK: omp.sections reduction(@add_f32 -> %{{.*}} : !llvm.ptr) "omp.sections" (%redn_var) ({ // CHECK: omp.terminator omp.terminator - }) {operand_segment_sizes = dense<[1,0,0]> : vector<3xi32>, reductions=[@add_f32]} : (!llvm.ptr) -> () + }) {operand_segment_sizes = array, reductions=[@add_f32]} : (!llvm.ptr) -> () // CHECK: omp.sections nowait { omp.sections nowait { diff --git a/mlir/test/Dialect/PDL/invalid.mlir b/mlir/test/Dialect/PDL/invalid.mlir --- a/mlir/test/Dialect/PDL/invalid.mlir +++ b/mlir/test/Dialect/PDL/invalid.mlir @@ -122,7 +122,7 @@ // 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 } : () -> (!pdl.operation) rewrite %op with "rewriter" } @@ -230,7 +230,7 @@ // 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 } : (!pdl.operation, !pdl.operation, !pdl.value) -> () } } @@ -259,7 +259,7 @@ // 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 } : (!pdl.operation) -> () } @@ -272,7 +272,7 @@ "pdl.rewrite"(%op, %op) ({ ^bb1: }) { - operand_segment_sizes = dense<1> : vector<2xi32> + operand_segment_sizes = array }: (!pdl.operation, !pdl.operation) -> () } @@ -286,7 +286,7 @@ ^bb1: }) { name = "foo", - operand_segment_sizes = dense<[1,0]> : vector<2xi32> + operand_segment_sizes = array } : (!pdl.operation) -> () } diff --git a/mlir/test/Dialect/PDLInterp/invalid.mlir b/mlir/test/Dialect/PDLInterp/invalid.mlir --- a/mlir/test/Dialect/PDLInterp/invalid.mlir +++ b/mlir/test/Dialect/PDLInterp/invalid.mlir @@ -19,8 +19,7 @@ inferredResultTypes, inputAttributeNames = [], name = "foo.op", - operand_segment_sizes = dense<[0, 0, 1]> : vector<3xi32> + operand_segment_sizes = array } : (!pdl.type) -> (!pdl.operation) pdl_interp.finalize } - diff --git a/mlir/test/Dialect/SCF/invalid.mlir b/mlir/test/Dialect/SCF/invalid.mlir --- a/mlir/test/Dialect/SCF/invalid.mlir +++ b/mlir/test/Dialect/SCF/invalid.mlir @@ -131,7 +131,7 @@ "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}: (index, index, index) -> () return } @@ -143,7 +143,7 @@ "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}: (index, index, index) -> () return } diff --git a/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir b/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir --- a/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir +++ b/mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir @@ -117,7 +117,7 @@ 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} : (i1) -> () ^one: spv.Return ^two: @@ -130,7 +130,7 @@ %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} : (i1) -> () ^one: spv.Return ^two: diff --git a/mlir/test/IR/parser.mlir b/mlir/test/IR/parser.mlir --- a/mlir/test/IR/parser.mlir +++ b/mlir/test/IR/parser.mlir @@ -457,7 +457,7 @@ ^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} : (i1, i17, i1, i17) -> () ^bb2(%a : i17): %true = arith.constant true diff --git a/mlir/test/IR/traits.mlir b/mlir/test/IR/traits.mlir --- a/mlir/test/IR/traits.mlir +++ b/mlir/test/IR/traits.mlir @@ -375,114 +375,101 @@ // ----- 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} : (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, 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, 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, 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, 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} : () -> (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, 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, 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, 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, i32, i32, i32) return } diff --git a/mlir/test/Rewrite/pdl-bytecode.mlir b/mlir/test/Rewrite/pdl-bytecode.mlir --- a/mlir/test/Rewrite/pdl-bytecode.mlir +++ b/mlir/test/Rewrite/pdl-bytecode.mlir @@ -1051,7 +1051,7 @@ // 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, i32, i32, i32, i32) -> () } // ----- @@ -1204,7 +1204,7 @@ // 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, i32, i32, i32, i32) "test.consumer"(%results#0, %results#1, %results#2, %results#3, %results#4) : (i32, i32, i32, i32, i32) -> () } diff --git a/mlir/test/Target/LLVMIR/openmp-llvm.mlir b/mlir/test/Target/LLVMIR/openmp-llvm.mlir --- a/mlir/test/Target/LLVMIR/openmp-llvm.mlir +++ b/mlir/test/Target/LLVMIR/openmp-llvm.mlir @@ -379,7 +379,7 @@ llvm.store %3, %4 : !llvm.ptr 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} : (i64, i64, i64) -> () omp.terminator } llvm.return @@ -399,7 +399,7 @@ %4 = llvm.getelementptr %arg0[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr llvm.store %3, %4 : !llvm.ptr omp.yield - }) {operand_segment_sizes = dense<[1, 1, 1, 0, 0, 0, 0]> : vector<7xi32>} : (i64, i64, i64) -> () + }) {operand_segment_sizes = array} : (i64, i64, i64) -> () llvm.return } @@ -417,7 +417,7 @@ %4 = llvm.getelementptr %arg0[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr llvm.store %3, %4 : !llvm.ptr omp.yield - }) {inclusive, operand_segment_sizes = dense<[1, 1, 1, 0, 0, 0, 0]> : vector<7xi32>} : (i64, i64, i64) -> () + }) {inclusive, operand_segment_sizes = array} : (i64, i64, i64) -> () llvm.return } @@ -697,8 +697,8 @@ %4 = llvm.getelementptr %arg0[%iv] : (!llvm.ptr, i64) -> !llvm.ptr llvm.store %3, %4 : !llvm.ptr omp.yield - }) {operand_segment_sizes = dense<[1,1,1,0]> : vector<4xi32>} : - (i64, i64, i64) -> () + }) {operand_segment_sizes = array} : + (i64, i64, i64) -> () llvm.return } @@ -720,7 +720,7 @@ llvm.store %3, %4 : !llvm.ptr llvm.store %3, %5 : !llvm.ptr omp.yield - } + } llvm.return } // CHECK: llvm.loop.parallel_accesses @@ -753,9 +753,9 @@ // CHECK-LABEL: @simdloop_if llvm.func @simdloop_if(%arg0: !llvm.ptr {fir.bindc_name = "n"}, %arg1: !llvm.ptr {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 + %1 = llvm.alloca %0 x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = array} : (i64) -> !llvm.ptr %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 + %3 = llvm.alloca %2 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array, uniq_name = "_QFtest_simdEi"} : (i64) -> !llvm.ptr %4 = llvm.mlir.constant(0 : i32) : i32 %5 = llvm.load %arg0 : !llvm.ptr %6 = llvm.mlir.constant(1 : i32) : i32 diff --git a/mlir/test/Transforms/canonicalize-block-merge.mlir b/mlir/test/Transforms/canonicalize-block-merge.mlir --- a/mlir/test/Transforms/canonicalize-block-merge.mlir +++ b/mlir/test/Transforms/canonicalize-block-merge.mlir @@ -257,7 +257,7 @@ 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 ^bb1: diff --git a/mlir/test/Transforms/sccp.mlir b/mlir/test/Transforms/sccp.mlir --- a/mlir/test/Transforms/sccp.mlir +++ b/mlir/test/Transforms/sccp.mlir @@ -204,7 +204,7 @@ // 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) -> () ^bb1: @@ -231,4 +231,3 @@ ^b: return %1 : i32 } - diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -716,14 +716,14 @@ Variadic:$b, I32:$c, Variadic:$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:$a, @@ -2056,7 +2056,7 @@ : TEST_Op<"format_variadic_of_variadic_operand"> { let arguments = (ins VariadicOfVariadic:$operand, - I32ElementsAttr:$operand_segments + DenseI32ArrayAttr:$operand_segments ); let assemblyFormat = [{ $operand `:` type($operand) attr-dict}]; } diff --git a/mlir/test/python/dialects/linalg/ops.py b/mlir/test/python/dialects/linalg/ops.py --- a/mlir/test/python/dialects/linalg/ops.py +++ b/mlir/test/python/dialects/linalg/ops.py @@ -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): @@ -138,7 +134,7 @@ # CHECK-NEXT: arith.addf{{.*}} (f32, f32) -> f32 # CHECK-NEXT: linalg.yield{{.*}} (f32) -> () # CHECK-NEXT: cast = #linalg.type_fn - # CHECK-SAME: operand_segment_sizes = dense<[2, 1]> : vector<2xi32> + # CHECK-SAME: operand_segment_sizes = array # CHECK-SAME: (tensor<4x16xf32>, tensor<16x8xf32>, tensor<4x8xf32>) -> tensor<4x8xf32> return linalg.matmul(lhs, rhs, outs=[init_result.result]) diff --git a/mlir/test/python/dialects/ods_helpers.py b/mlir/test/python/dialects/ods_helpers.py --- a/mlir/test/python/dialects/ods_helpers.py +++ b/mlir/test/python/dialects/ods_helpers.py @@ -1,8 +1,10 @@ # RUN: %PYTHON %s | FileCheck %s import gc + from mlir.ir import * + def run(f): print("\nTEST:", f.__name__) f() @@ -125,8 +127,8 @@ # 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 + # CHECK-SAME: result_segment_sizes = array>] # CHECK-SAME: : (i32, i32, i32, i32) -> (i8, i16, i32, i64) op = TestOp.build_generic( results=[[t0, t1], t2, t3], diff --git a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -94,27 +94,23 @@ /// 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(); - 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 @@ -124,13 +120,12 @@ /// {1}: The index of the main operand. static const char *const variadicOfVariadicAdaptorCalcCode = R"( auto tblgenTmpOperands = getODSOperands({1}); - auto sizeAttrValues = {0}().getValues(); - 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; )"; @@ -608,9 +603,8 @@ // {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; @@ -2056,7 +2050,7 @@ << op.getGetterName( operand.constraint.getVariadicOfVariadicSegmentSizeAttr()) << "AttrName(" << builderOpState << ".name), " << odsBuilder - << ".getI32TensorAttr(rangeSegments));" + << ".getDenseI32ArrayAttr(rangeSegments));" << " }\n"; continue; } @@ -2071,7 +2065,7 @@ std::string sizes = op.getGetterName(operandSegmentAttrName); body << " " << builderOpState << ".addAttribute(" << sizes << "AttrName(" << builderOpState << ".name), " - << "odsBuilder.getI32VectorAttr({"; + << "odsBuilder.getDenseI32ArrayAttr({"; interleaveComma(llvm::seq(0, op.getNumOperands()), body, [&](int i) { const NamedTypeConstraint &operand = op.getOperand(i); if (!operand.isVariableLength()) { diff --git a/mlir/tools/mlir-tblgen/OpFormatGen.cpp b/mlir/tools/mlir-tblgen/OpFormatGen.cpp --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -1558,7 +1558,7 @@ 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()) @@ -1574,7 +1574,7 @@ continue; body << llvm::formatv( " result.addAttribute(\"{0}\", " - "parser.getBuilder().getI32TensorAttr({1}OperandGroupSizes));\n", + "parser.getBuilder().getDenseI32ArrayAttr({1}OperandGroupSizes));\n", operand.constraint.getVariadicOfVariadicSegmentSizeAttr(), operand.name); } @@ -1583,7 +1583,7 @@ 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())