From e8e718fa4b850d93a94ff47d55869401f0285d98 Mon Sep 17 00:00:00 2001 From: Alex Zinenko Date: Fri, 12 Aug 2022 10:17:48 +0200 Subject: [PATCH] Revert "[mlir] Switch segment size attributes to DenseI32ArrayAttr" This reverts commit 30171e76f0e5ea8037bc4d1450dd3e12af4d9938. Breaks Python tests in MLIR, missing C API and Python changes. --- flang/include/flang/Optimizer/Dialect/FIROps.td | 6 +- flang/lib/Lower/OpenACC.cpp | 4 +- flang/lib/Optimizer/Dialect/FIROps.cpp | 115 ++++++++++----------- flang/test/Fir/convert-to-llvm-openmp-and-fir.fir | 4 +- flang/test/Fir/convert-to-llvm.fir | 8 +- mlir/docs/PatternRewriter.md | 2 +- .../mlir/Dialect/ControlFlow/IR/ControlFlowOps.td | 2 +- mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td | 2 +- mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td | 2 +- .../mlir/Dialect/PDLInterp/IR/PDLInterpOps.td | 2 +- mlir/include/mlir/IR/ValueRange.h | 8 +- mlir/lib/Dialect/Async/IR/Async.cpp | 10 +- .../Dialect/Bufferization/IR/BufferizationOps.cpp | 2 +- mlir/lib/Dialect/GPU/IR/GPUDialect.cpp | 12 +-- mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp | 10 +- mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp | 8 +- mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp | 6 +- mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp | 4 +- mlir/lib/Dialect/SCF/IR/SCF.cpp | 16 +-- mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp | 8 +- mlir/lib/Dialect/Vector/IR/VectorOps.cpp | 16 +-- mlir/lib/IR/Operation.cpp | 21 ++-- mlir/lib/IR/OperationSupport.cpp | 23 +++-- mlir/lib/Rewrite/ByteCode.cpp | 6 +- mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp | 2 +- .../Conversion/OpenMPToLLVM/convert-to-llvmir.mlir | 4 +- mlir/test/Dialect/GPU/invalid.mlir | 8 +- mlir/test/Dialect/Linalg/named-ops.mlir | 4 +- mlir/test/Dialect/OpenMP/invalid.mlir | 20 ++-- mlir/test/Dialect/OpenMP/ops.mlir | 30 +++--- mlir/test/Dialect/PDL/invalid.mlir | 10 +- mlir/test/Dialect/PDLInterp/invalid.mlir | 3 +- mlir/test/Dialect/SCF/invalid.mlir | 4 +- mlir/test/Dialect/SPIRV/IR/control-flow-ops.mlir | 4 +- mlir/test/IR/parser.mlir | 2 +- mlir/test/IR/traits.mlir | 45 +++++--- mlir/test/Rewrite/pdl-bytecode.mlir | 4 +- mlir/test/Target/LLVMIR/openmp-llvm.mlir | 16 +-- mlir/test/Transforms/canonicalize-block-merge.mlir | 2 +- mlir/test/Transforms/sccp.mlir | 3 +- mlir/test/lib/Dialect/Test/TestOps.td | 6 +- mlir/test/python/dialects/linalg/ops.py | 10 +- mlir/test/python/dialects/ods_helpers.py | 6 +- mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp | 30 +++--- mlir/tools/mlir-tblgen/OpFormatGen.cpp | 6 +- 45 files changed, 272 insertions(+), 244 deletions(-) diff --git a/flang/include/flang/Optimizer/Dialect/FIROps.td b/flang/include/flang/Optimizer/Dialect/FIROps.td index ff0642b..e7d8fa4 100644 --- a/flang/include/flang/Optimizer/Dialect/FIROps.td +++ b/flang/include/flang/Optimizer/Dialect/FIROps.td @@ -417,7 +417,7 @@ def fir_UndefOp : fir_OneResultOp<"undefined", [NoSideEffect]> { 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 @@ class fir_IntegralSwitchTerminatorOp]; diff --git a/flang/lib/Lower/OpenACC.cpp b/flang/lib/Lower/OpenACC.cpp index 4b55c8b..2259060 100644 --- a/flang/lib/Lower/OpenACC.cpp +++ b/flang/lib/Lower/OpenACC.cpp @@ -113,7 +113,7 @@ createRegionOp(fir::FirOpBuilder &builder, mlir::Location loc, builder.create(loc); op->setAttr(Op::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr(operandSegments)); + builder.getI32VectorAttr(operandSegments)); // Place the insertion point to the start of the first block. builder.setInsertionPointToStart(&block); @@ -129,7 +129,7 @@ createSimpleOp(fir::FirOpBuilder &builder, mlir::Location loc, llvm::ArrayRef argTy; Op op = builder.create(loc, argTy, operands); op->setAttr(Op::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr(operandSegments)); + builder.getI32VectorAttr(operandSegments)); return op; } diff --git a/flang/lib/Optimizer/Dialect/FIROps.cpp b/flang/lib/Optimizer/Dialect/FIROps.cpp index 1c1e1a6..6db08c9 100644 --- a/flang/lib/Optimizer/Dialect/FIROps.cpp +++ b/flang/lib/Optimizer/Dialect/FIROps.cpp @@ -126,9 +126,8 @@ static mlir::ParseResult parseAllocatableOp(FN wrapResultType, parser.emitError(parser.getNameLoc(), "invalid allocate type: ") << intype; return mlir::failure(); } - result.addAttribute( - "operand_segment_sizes", - builder.getDenseI32ArrayAttr({typeparamsSize, shapeSize})); + result.addAttribute("operand_segment_sizes", + builder.getI32VectorAttr({typeparamsSize, shapeSize})); if (parser.parseOptionalAttrDict(result.attributes) || parser.addTypeToList(restype, result.types)) return mlir::failure(); @@ -2432,8 +2431,8 @@ static mlir::ParseResult parseIntegralSwitchTerminator( sumArgs += argSize; } result.addAttribute(operandSegmentAttr, - bld.getDenseI32ArrayAttr({1, 0, sumArgs})); - result.addAttribute(getTargetOffsetAttr(), bld.getDenseI32ArrayAttr(argOffs)); + bld.getI32VectorAttr({1, 0, sumArgs})); + result.addAttribute(getTargetOffsetAttr(), bld.getI32VectorAttr(argOffs)); return mlir::success(); } @@ -2481,12 +2480,13 @@ void fir::SelectOp::print(mlir::OpAsmPrinter &p) { } template -static A getSubOperands(unsigned pos, A allArgs, mlir::DenseI32ArrayAttr ranges, +static A getSubOperands(unsigned pos, A allArgs, + mlir::DenseIntElementsAttr ranges, AdditionalArgs &&...additionalArgs) { unsigned start = 0; for (unsigned i = 0; i < pos; ++i) - start += ranges[i]; - return allArgs.slice(start, ranges[pos], + start += (*(ranges.begin() + i)).getZExtValue(); + return allArgs.slice(start, (*(ranges.begin() + pos)).getZExtValue(), std::forward(additionalArgs)...); } @@ -2498,10 +2498,14 @@ getMutableSuccessorOperands(unsigned pos, mlir::MutableOperandRange operands, *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 {}; } @@ -2520,8 +2524,8 @@ llvm::Optional> 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)}; } @@ -2529,16 +2533,15 @@ fir::SelectOp::getSuccessorOperands(llvm::ArrayRef operands, 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 (*this) - ->getAttrOfType(getTargetOffsetAttr()) - .size(); + return denseElementsSize((*this)->getAttrOfType( + getTargetOffsetAttr())); } //===----------------------------------------------------------------------===// @@ -2547,17 +2550,17 @@ unsigned fir::SelectOp::targetOffsetSize() { 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)}; } @@ -2565,9 +2568,9 @@ fir::SelectCaseOp::getCompareOperands(llvm::ArrayRef operands, 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)}; } @@ -2581,8 +2584,8 @@ llvm::Optional> 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)}; } @@ -2591,8 +2594,8 @@ llvm::Optional 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)}; } @@ -2665,11 +2668,9 @@ mlir::ParseResult fir::SelectCaseOp::parse(mlir::OpAsmParser &parser, } auto &bld = parser.getBuilder(); result.addAttribute(fir::SelectCaseOp::getOperandSegmentSizeAttr(), - bld.getDenseI32ArrayAttr({1, offSize, toffSize})); - result.addAttribute(getCompareOffsetAttr(), - bld.getDenseI32ArrayAttr(argOffs)); - result.addAttribute(getTargetOffsetAttr(), - bld.getDenseI32ArrayAttr(targOffs)); + bld.getI32VectorAttr({1, offSize, toffSize})); + result.addAttribute(getCompareOffsetAttr(), bld.getI32VectorAttr(argOffs)); + result.addAttribute(getTargetOffsetAttr(), bld.getI32VectorAttr(targOffs)); return mlir::success(); } @@ -2702,15 +2703,13 @@ void fir::SelectCaseOp::print(mlir::OpAsmPrinter &p) { } unsigned fir::SelectCaseOp::compareOffsetSize() { - return (*this) - ->getAttrOfType(getCompareOffsetAttr()) - .size(); + return denseElementsSize((*this)->getAttrOfType( + getCompareOffsetAttr())); } unsigned fir::SelectCaseOp::targetOffsetSize() { - return (*this) - ->getAttrOfType(getTargetOffsetAttr()) - .size(); + return denseElementsSize((*this)->getAttrOfType( + getTargetOffsetAttr())); } void fir::SelectCaseOp::build(mlir::OpBuilder &builder, @@ -2739,7 +2738,7 @@ void fir::SelectCaseOp::build(mlir::OpBuilder &builder, for (auto ops : cmpOperands) result.addOperands(ops); result.addAttribute(getCompareOffsetAttr(), - builder.getDenseI32ArrayAttr(operOffs)); + builder.getI32VectorAttr(operOffs)); const auto count = destinations.size(); for (auto d : destinations) result.addSuccessors(d); @@ -2757,9 +2756,8 @@ void fir::SelectCaseOp::build(mlir::OpBuilder &builder, } } result.addAttribute(getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr({1, operSize, sumArgs})); - result.addAttribute(getTargetOffsetAttr(), - builder.getDenseI32ArrayAttr(argOffs)); + builder.getI32VectorAttr({1, operSize, sumArgs})); + result.addAttribute(getTargetOffsetAttr(), builder.getI32VectorAttr(argOffs)); result.addAttributes(attributes); } @@ -2856,8 +2854,8 @@ llvm::Optional> 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)}; } @@ -2866,16 +2864,15 @@ llvm::Optional 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 (*this) - ->getAttrOfType(getTargetOffsetAttr()) - .size(); + return denseElementsSize((*this)->getAttrOfType( + getTargetOffsetAttr())); } //===----------------------------------------------------------------------===// @@ -2901,8 +2898,8 @@ llvm::Optional> 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)}; } @@ -2947,15 +2944,14 @@ mlir::ParseResult fir::SelectTypeOp::parse(mlir::OpAsmParser &parser, offSize += argSize; } result.addAttribute(fir::SelectTypeOp::getOperandSegmentSizeAttr(), - bld.getDenseI32ArrayAttr({1, 0, offSize})); - result.addAttribute(getTargetOffsetAttr(), bld.getDenseI32ArrayAttr(argOffs)); + bld.getI32VectorAttr({1, 0, offSize})); + result.addAttribute(getTargetOffsetAttr(), bld.getI32VectorAttr(argOffs)); return mlir::success(); } unsigned fir::SelectTypeOp::targetOffsetSize() { - return (*this) - ->getAttrOfType(getTargetOffsetAttr()) - .size(); + return denseElementsSize((*this)->getAttrOfType( + getTargetOffsetAttr())); } void fir::SelectTypeOp::print(mlir::OpAsmPrinter &p) { @@ -3025,9 +3021,8 @@ void fir::SelectTypeOp::build(mlir::OpBuilder &builder, } } result.addAttribute(getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr({1, 0, sumArgs})); - result.addAttribute(getTargetOffsetAttr(), - builder.getDenseI32ArrayAttr(argOffs)); + builder.getI32VectorAttr({1, 0, sumArgs})); + result.addAttribute(getTargetOffsetAttr(), builder.getI32VectorAttr(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 index d40e69d..c600878 100644 --- 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 @@ func.func @_QPsb1(%arg0: !fir.ref {fir.bindc_name = "n"}, %arg1: !fir.ref, pinned} : (i64) -> !llvm.ptr +// 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: %[[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 @@ func.func @_QPsimd1(%arg0: !fir.ref {fir.bindc_name = "n"}, %arg1: !fir.ref // 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 = array, pinned} : (i64) -> !llvm.ptr +// 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: %[[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 index 2bd27ee..388f465 100644 --- a/flang/test/Fir/convert-to-llvm.fir +++ b/flang/test/Fir/convert-to-llvm.fir @@ -1701,7 +1701,7 @@ func.func @no_reassoc(%arg0: !fir.ref) { // 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 = array} : (i64) -> !llvm.ptr +// CHECK: %[[ALLOC:.*]] = llvm.alloca %[[C1]] x i32 {in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>} : (i64) -> !llvm.ptr // CHECK: %[[LOAD:.*]] = llvm.load %[[ARG0]] : !llvm.ptr // CHECK: llvm.store %[[LOAD]], %[[ALLOC]] : !llvm.ptr // CHECK: llvm.return @@ -1821,7 +1821,7 @@ func.func private @_QPxb(!fir.box>) // 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 = array, uniq_name = "_QFsbEarr"} : (i64) -> !llvm.ptr +// 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: %[[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 @@ func.func private @_QPtest_dt_callee(%arg0: !fir.box>) // 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 = array, 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 = dense<0> : vector<2xi32>, 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 = array, 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 = dense<0> : vector<2xi32>, 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 index 3ae6547..d221ce9 100644 --- a/mlir/docs/PatternRewriter.md +++ b/mlir/docs/PatternRewriter.md @@ -357,7 +357,7 @@ Example output is shown below: ``` //===-------------------------------------------===// Processing operation : 'cf.cond_br'(0x60f000001120) { - "cf.cond_br"(%arg0)[^bb2, ^bb2] {operand_segment_sizes = array} : (i1) -> () + "cf.cond_br"(%arg0)[^bb2, ^bb2] {operand_segment_sizes = dense<[1, 0, 0]> : vector<3xi32>} : (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 index baba706..94c5323 100644 --- a/mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.td +++ b/mlir/include/mlir/Dialect/ControlFlow/IR/ControlFlowOps.td @@ -254,7 +254,7 @@ def SwitchOp : CF_Op<"switch", Variadic:$defaultOperands, VariadicOfVariadic:$caseOperands, OptionalAttr:$case_values, - DenseI32ArrayAttr:$case_operand_segments + I32ElementsAttr:$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 index b9b0256..84fc592 100644 --- a/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td +++ b/mlir/include/mlir/Dialect/LLVMIR/LLVMOps.td @@ -915,7 +915,7 @@ def LLVM_SwitchOp : LLVM_TerminatorOp<"switch", Variadic:$defaultOperands, VariadicOfVariadic:$caseOperands, OptionalAttr:$case_values, - DenseI32ArrayAttr:$case_operand_segments, + ElementsAttr:$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 index d397d29..cd1b87d 100644 --- a/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td +++ b/mlir/include/mlir/Dialect/MemRef/IR/MemRefOps.td @@ -86,7 +86,7 @@ class AllocLikeOp(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 index 6d32892..44dc6cd 100644 --- a/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td +++ b/mlir/include/mlir/Dialect/PDLInterp/IR/PDLInterpOps.td @@ -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} -> diff --git a/mlir/include/mlir/IR/ValueRange.h b/mlir/include/mlir/IR/ValueRange.h index 64b816f..6fb35ea 100644 --- a/mlir/include/mlir/IR/ValueRange.h +++ b/mlir/include/mlir/IR/ValueRange.h @@ -13,7 +13,6 @@ #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" @@ -23,6 +22,7 @@ namespace mlir { class ValueRange; template class ValueTypeRange; +class ElementsAttr; class TypeRangeRange; template class ValueTypeIterator; @@ -54,7 +54,7 @@ public: /// Split this range into a set of contiguous subranges using the given /// elements attribute, which contains the sizes of the sub ranges. - OperandRangeRange split(DenseI32ArrayAttr segmentSizes) const; + OperandRangeRange split(ElementsAttr segmentSizes) const; private: /// See `llvm::detail::indexed_accessor_range_base` for details. @@ -114,8 +114,8 @@ private: 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 a - /// dense i32 array attr. + /// and the index within that attribute. The attribute should correspond to an + /// i32 DenseElementsAttr. 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 index 8a68e0d..7331e5f 100644 --- a/mlir/lib/Dialect/Async/IR/Async.cpp +++ b/mlir/lib/Dialect/Async/IR/Async.cpp @@ -97,8 +97,9 @@ 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 = - builder.getDenseI32ArrayAttr({numDependencies, numOperands}); + auto operandSegmentSizes = DenseIntElementsAttr::get( + VectorType::get({2}, builder.getIntegerType(32)), + {numDependencies, numOperands}); result.addAttribute(kOperandSegmentSizesAttr, operandSegmentSizes); // First result is always a token, and then `resultTypes` wrapped into @@ -202,8 +203,9 @@ ParseResult ExecuteOp::parse(OpAsmParser &parser, OperationState &result) { int32_t numOperands = valueArgs.size(); // Add derived `operand_segment_sizes` attribute based on parsed operands. - auto operandSegmentSizes = - parser.getBuilder().getDenseI32ArrayAttr({numDependencies, numOperands}); + auto operandSegmentSizes = DenseIntElementsAttr::get( + VectorType::get({2}, parser.getBuilder().getI32Type()), + {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 index 9ca51f8..c4bad43 100644 --- a/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp +++ b/mlir/lib/Dialect/Bufferization/IR/BufferizationOps.cpp @@ -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().getDenseI32ArrayAttr( + parser.getBuilder().getI32VectorAttr( {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 index d564f53..d102dbe 100644 --- a/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp +++ b/mlir/lib/Dialect/GPU/IR/GPUDialect.cpp @@ -374,15 +374,15 @@ void gpu::addAsyncDependency(Operation *op, Value token) { 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.asArrayRef()); + SmallVector sizes(sizeAttr.getValues()); ++sizes.front(); - op->setAttr(attrName, Builder(op->getContext()).getDenseI32ArrayAttr(sizes)); + op->setAttr(attrName, Builder(op->getContext()).getI32VectorAttr(sizes)); } //===----------------------------------------------------------------------===// @@ -416,7 +416,7 @@ void LaunchOp::build(OpBuilder &builder, OperationState &result, segmentSizes.front() = asyncDependencies.size(); segmentSizes.back() = dynamicSharedMemorySize ? 1 : 0; result.addAttribute(getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr(segmentSizes)); + builder.getI32VectorAttr(segmentSizes)); } KernelDim3 LaunchOp::getBlockIds() { @@ -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().getDenseI32ArrayAttr(segmentSizes)); + parser.getBuilder().getI32VectorAttr(segmentSizes)); return success(); } @@ -709,7 +709,7 @@ void LaunchFuncOp::build(OpBuilder &builder, OperationState &result, segmentSizes[segmentSizes.size() - 2] = dynamicSharedMemorySize ? 1 : 0; segmentSizes.back() = static_cast(kernelOperands.size()); result.addAttribute(getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr(segmentSizes)); + builder.getI32VectorAttr(segmentSizes)); } StringAttr LaunchFuncOp::getKernelModuleName() { diff --git a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp index a92cfbd..7c4f1a4 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/LLVMDialect.cpp @@ -1048,11 +1048,11 @@ ParseResult InvokeOp::parse(OpAsmParser &parser, OperationState &result) { result.addOperands(normalOperands); result.addOperands(unwindOperands); - result.addAttribute(InvokeOp::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr( - {static_cast(operands.size()), - static_cast(normalOperands.size()), - static_cast(unwindOperands.size())})); + result.addAttribute( + InvokeOp::getOperandSegmentSizeAttr(), + builder.getI32VectorAttr({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 index 1b1e0e7..b28ef14 100644 --- a/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp +++ b/mlir/lib/Dialect/LLVMIR/IR/NVVMDialect.cpp @@ -233,9 +233,9 @@ void MmaOp::build(OpBuilder &builder, OperationState &result, Type resultType, result.addTypes(resultType); result.addAttribute( MmaOp::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr({static_cast(operandA.size()), - static_cast(operandB.size()), - static_cast(operandC.size())})); + builder.getI32VectorAttr({static_cast(operandA.size()), + static_cast(operandB.size()), + static_cast(operandC.size())})); } // := @@ -326,7 +326,7 @@ ParseResult MmaOp::parse(OpAsmParser &parser, OperationState &result) { if (!namedAttributes.empty()) result.addAttributes(namedAttributes); result.addAttribute(MmaOp::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr({ + builder.getI32VectorAttr({ 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 index 74b503c..650d7a2 100644 --- a/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp +++ b/mlir/lib/Dialect/Linalg/IR/LinalgOps.cpp @@ -111,8 +111,8 @@ static void buildStructuredOp(OpBuilder &b, OperationState &state, state.addAttributes(attributes); state.addAttribute( "operand_segment_sizes", - b.getDenseI32ArrayAttr({static_cast(inputs.size()), - static_cast(outputs.size())})); + b.getI32VectorAttr({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 @@ parseCommonStructuredOpParts(OpAsmParser &parser, OperationState &result, return failure(); result.addAttribute("operand_segment_sizes", - parser.getBuilder().getDenseI32ArrayAttr( + parser.getBuilder().getI32VectorAttr( {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 index 82e276e..b2960a6 100644 --- a/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp +++ b/mlir/lib/Dialect/OpenACC/IR/OpenACC.cpp @@ -361,7 +361,7 @@ ParseResult ParallelOp::parse(OpAsmParser &parser, OperationState &result) { result.addAttribute( ParallelOp::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr( + builder.getI32VectorAttr( {static_cast(async.has_value() ? 1 : 0), static_cast(waitOperands.size()), static_cast(numGangs.has_value() ? 1 : 0), @@ -590,7 +590,7 @@ ParseResult LoopOp::parse(OpAsmParser &parser, OperationState &result) { return failure(); result.addAttribute(LoopOp::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr( + builder.getI32VectorAttr( {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 index 0198295..607811a 100644 --- a/mlir/lib/Dialect/SCF/IR/SCF.cpp +++ b/mlir/lib/Dialect/SCF/IR/SCF.cpp @@ -2105,10 +2105,10 @@ void ParallelOp::build( result.addOperands(initVals); result.addAttribute( ParallelOp::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr({static_cast(lowerBounds.size()), - static_cast(upperBounds.size()), - static_cast(steps.size()), - static_cast(initVals.size())})); + builder.getI32VectorAttr({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 @@ ParseResult ParallelOp::parse(OpAsmParser &parser, OperationState &result) { // Set `operand_segment_sizes` attribute. result.addAttribute( ParallelOp::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr({static_cast(lower.size()), - static_cast(upper.size()), - static_cast(steps.size()), - static_cast(initVals.size())})); + builder.getI32VectorAttr({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 index eaa623f..f7758f9 100644 --- a/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp +++ b/mlir/lib/Dialect/SPIRV/IR/SPIRVOps.cpp @@ -1579,10 +1579,10 @@ ParseResult spirv::BranchConditionalOp::parse(OpAsmParser &parser, return failure(); result.addSuccessors(dest); result.addOperands(falseOperands); - result.addAttribute(spirv::BranchConditionalOp::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr( - {1, static_cast(trueOperands.size()), - static_cast(falseOperands.size())})); + result.addAttribute( + spirv::BranchConditionalOp::getOperandSegmentSizeAttr(), + builder.getI32VectorAttr({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 index c971cd8..ce494c3 100644 --- a/mlir/lib/Dialect/Vector/IR/VectorOps.cpp +++ b/mlir/lib/Dialect/Vector/IR/VectorOps.cpp @@ -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.getDenseI32ArrayAttr( - {1, static_cast(indexInfo.size()), 1, - static_cast(hasMask.succeeded())})); + result.addAttribute( + TransferReadOp::getOperandSegmentSizeAttr(), + builder.getI32VectorAttr({1, static_cast(indexInfo.size()), 1, + static_cast(hasMask.succeeded())})); return parser.addTypeToList(vectorType, result.types); } @@ -3465,10 +3465,10 @@ ParseResult TransferWriteOp::parse(OpAsmParser &parser, if (parser.resolveOperand(maskInfo, maskType, result.operands)) return failure(); } - result.addAttribute(TransferWriteOp::getOperandSegmentSizeAttr(), - builder.getDenseI32ArrayAttr( - {1, 1, static_cast(indexInfo.size()), - static_cast(hasMask.succeeded())})); + result.addAttribute( + TransferWriteOp::getOperandSegmentSizeAttr(), + builder.getI32VectorAttr({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 index e30d5ea..b255e80 100644 --- a/mlir/lib/IR/Operation.cpp +++ b/mlir/lib/IR/Operation.cpp @@ -987,19 +987,26 @@ LogicalResult OpTrait::impl::verifyValueSizeAttr(Operation *op, StringRef attrName, StringRef valueGroupName, size_t expectedCount) { - auto sizeAttr = op->getAttrOfType(attrName); + auto sizeAttr = op->getAttrOfType(attrName); if (!sizeAttr) - return op->emitOpError("requires dense i32 array attribute '") + return op->emitOpError("requires 1D i32 elements attribute '") << attrName << "'"; - ArrayRef sizes = sizeAttr.asArrayRef(); - if (llvm::any_of(sizes, [](int32_t element) { return element < 0; })) + 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(); + })) return op->emitOpError("'") << attrName << "' attribute cannot have negative elements"; - size_t totalCount = - std::accumulate(sizes.begin(), sizes.end(), 0, - [](unsigned all, int32_t one) { return all + one; }); + size_t totalCount = std::accumulate( + sizeAttr.begin(), sizeAttr.end(), 0, + [](unsigned all, const APInt &one) { return all + one.getZExtValue(); }); if (totalCount != expectedCount) return op->emitOpError() diff --git a/mlir/lib/IR/OperationSupport.cpp b/mlir/lib/IR/OperationSupport.cpp index 53d55ef..1f7a739 100644 --- a/mlir/lib/IR/OperationSupport.cpp +++ b/mlir/lib/IR/OperationSupport.cpp @@ -377,7 +377,7 @@ unsigned OperandRange::getBeginOperandIndex() const { return base->getOperandNumber(); } -OperandRangeRange OperandRange::split(DenseI32ArrayAttr segmentSizes) const { +OperandRangeRange OperandRange::split(ElementsAttr segmentSizes) const { return OperandRangeRange(*this, segmentSizes); } @@ -387,18 +387,18 @@ OperandRangeRange OperandRange::split(DenseI32ArrayAttr segmentSizes) const { 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(); - ArrayRef sizeData = owner.second.cast(); + auto sizeData = owner.second.cast().getValues(); return OperandRange(owner.first, std::accumulate(sizeData.begin(), sizeData.end(), 0)); } OperandRange OperandRangeRange::dereference(const OwnerT &object, ptrdiff_t index) { - ArrayRef sizeData = object.second.cast(); + auto sizeData = object.second.cast().getValues(); uint32_t startIndex = std::accumulate(sizeData.begin(), sizeData.begin() + index, 0); return OperandRange(object.first + startIndex, *(sizeData.begin() + index)); @@ -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(); - SmallVector segments(attr.asArrayRef()); + auto attr = segment.second.getValue().cast(); + SmallVector segments(attr.getValues()); segments[segment.first] += diff; segment.second.setValue( - DenseI32ArrayAttr::get(attr.getContext(), segments)); + DenseIntElementsAttr::get(attr.getType(), segments)); owner->setAttr(segment.second.getName(), segment.second.getValue()); } } @@ -506,20 +506,21 @@ MutableOperandRangeRange::MutableOperandRangeRange( 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()); + return OperandRangeRange( + getBase().first, getBase().second.getValue().cast()); } MutableOperandRange MutableOperandRangeRange::dereference(const OwnerT &object, ptrdiff_t index) { - ArrayRef sizeData = - object.second.getValue().cast(); + auto sizeData = + object.second.getValue().cast().getValues(); 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 index 388d6dc..d4ca8b2 100644 --- a/mlir/lib/Rewrite/ByteCode.cpp +++ b/mlir/lib/Rewrite/ByteCode.cpp @@ -1713,11 +1713,11 @@ executeGetOperandsResults(RangeT values, Operation *op, unsigned index, LLVM_DEBUG(llvm::dbgs() << " * Extracting values from `" << attrSizedSegments << "`\n"); - auto segmentAttr = op->getAttrOfType(attrSizedSegments); - if (!segmentAttr || segmentAttr.asArrayRef().size() <= index) + auto segmentAttr = op->getAttrOfType(attrSizedSegments); + if (!segmentAttr || segmentAttr.getNumElements() <= index) return nullptr; - ArrayRef segments = segmentAttr; + auto segments = segmentAttr.getValues(); 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 index 92ec7d1..089d20a 100644 --- a/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp +++ b/mlir/lib/Target/LLVMIR/ConvertFromLLVMIR.cpp @@ -906,7 +906,7 @@ LogicalResult Importer::processInstruction(llvm::Instruction *inst) { if (brInst->isConditional()) { state.addAttribute(LLVM::CondBrOp::getOperandSegmentSizeAttr(), - b.getDenseI32ArrayAttr(operandSegmentSizes)); + b.getI32VectorAttr(operandSegmentSizes)); } b.create(state); diff --git a/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir b/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir index b457811..b9dcbb4 100644 --- a/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir +++ b/mlir/test/Conversion/OpenMPToLLVM/convert-to-llvmir.mlir @@ -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 = array} : (index, index, index, index, index, index) -> () + }) {operand_segment_sizes = dense<[2, 2, 2, 0, 0, 0, 0]> : vector<7xi32>} : (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 index 877ba26..9a8f884 100644 --- a/mlir/test/Dialect/GPU/invalid.mlir +++ b/mlir/test/Dialect/GPU/invalid.mlir @@ -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 = array} : (index, index, index, index, index) -> () + }) {operand_segment_sizes = dense<[0, 1, 1, 1, 1, 1, 1, 0]> : vector<8xi32>} : (index, index, index, index, index) -> () return } @@ -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 = array} : (index, index, index, index, index, index) -> () + }) {operand_segment_sizes = dense<[0, 1, 1, 1, 1, 1, 1, 0]> : vector<8xi32>} : (index, index, index, index, index, index) -> () return } @@ -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 = array} + {operand_segment_sizes = dense<[0, 1, 1, 1, 1, 1, 0, 0]> : vector<8xi32>} : (index, index, index, index, index) -> () return } @@ -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 = array} + {operand_segment_sizes = dense<[0, 1, 1, 1, 1, 1, 1, 0, 0]> : vector<9xi32>} : (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 index 6512847..9c60df3 100644 --- a/mlir/test/Dialect/Linalg/named-ops.mlir +++ b/mlir/test/Dialect/Linalg/named-ops.mlir @@ -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 = array, strides = dense<2> : tensor<2xi64>} : (tensor, tensor, tensor) -> tensor + }) {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 return %0 : tensor } @@ -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 = array, strides = dense<1> : tensor<2xi64>} : (tensor, tensor, tensor) -> tensor + }) {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 return %0 : tensor } diff --git a/mlir/test/Dialect/OpenMP/invalid.mlir b/mlir/test/Dialect/OpenMP/invalid.mlir index c833bdd..6e62773 100644 --- a/mlir/test/Dialect/OpenMP/invalid.mlir +++ b/mlir/test/Dialect/OpenMP/invalid.mlir @@ -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 = array} : - (index, index, i32) -> () + }) {operand_segment_sizes = dense<[1,1,1,0]> : vector<4xi32>} : + (index, index, i32) -> () return } @@ -985,7 +985,7 @@ func.func @omp_sections(%data_var : memref) -> () { // expected-error @below {{expected equal sizes for allocate and allocator variables}} "omp.sections" (%data_var) ({ omp.terminator - }) {operand_segment_sizes = array} : (memref) -> () + }) {operand_segment_sizes = dense<[0,1,0]> : vector<3xi32>} : (memref) -> () return } @@ -995,7 +995,7 @@ func.func @omp_sections(%data_var : memref) -> () { // expected-error @below {{expected as many reduction symbol references as reduction variables}} "omp.sections" (%data_var) ({ omp.terminator - }) {operand_segment_sizes = array} : (memref) -> () + }) {operand_segment_sizes = dense<[1,0,0]> : vector<3xi32>} : (memref) -> () return } @@ -1110,7 +1110,7 @@ func.func @omp_single(%data_var : memref) -> () { // expected-error @below {{expected equal sizes for allocate and allocator variables}} "omp.single" (%data_var) ({ omp.barrier - }) {operand_segment_sizes = array} : (memref) -> () + }) {operand_segment_sizes = dense<[1,0]> : vector<2xi32>} : (memref) -> () return } @@ -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 = array} : (i32, i32, i32, i32, i32, i32, memref) -> () + }) {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) -> () return } @@ -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 = array, reductions = [@add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr) -> () + }) {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) -> () return } @@ -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 = array, reductions = [@add_f32, @add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr) -> () + }) {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) -> () return } @@ -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 = array} : (i32, i32, i32, i32, i32, i32, !llvm.ptr, !llvm.ptr) -> () + }) {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) -> () return } @@ -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 = array} : (i32, i32, i32, i32, i32, i32, !llvm.ptr) -> () + }) {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) -> () return } diff --git a/mlir/test/Dialect/OpenMP/ops.mlir b/mlir/test/Dialect/OpenMP/ops.mlir index 99c35fc..6e28324 100644 --- a/mlir/test/Dialect/OpenMP/ops.mlir +++ b/mlir/test/Dialect/OpenMP/ops.mlir @@ -59,7 +59,7 @@ func.func @omp_parallel(%data_var : memref, %if_cond : i1, %num_threads : i // CHECK: omp.parallel num_threads(%{{.*}} : i32) allocate(%{{.*}} : memref -> %{{.*}} : memref) "omp.parallel"(%num_threads, %data_var, %data_var) ({ omp.terminator - }) {operand_segment_sizes = array} : (i32, memref, memref) -> () + }) {operand_segment_sizes = dense<[0,1,1,1,0]> : vector<5xi32>} : (i32, memref, memref) -> () // CHECK: omp.barrier omp.barrier @@ -68,22 +68,22 @@ func.func @omp_parallel(%data_var : memref, %if_cond : i1, %num_threads : i // CHECK: omp.parallel if(%{{.*}}) allocate(%{{.*}} : memref -> %{{.*}} : memref) "omp.parallel"(%if_cond, %data_var, %data_var) ({ omp.terminator - }) {operand_segment_sizes = array} : (i1, memref, memref) -> () + }) {operand_segment_sizes = dense<[1,0,1,1,0]> : vector<5xi32>} : (i1, memref, memref) -> () // test without allocate // CHECK: omp.parallel if(%{{.*}}) num_threads(%{{.*}} : i32) "omp.parallel"(%if_cond, %num_threads) ({ omp.terminator - }) {operand_segment_sizes = array} : (i1, i32) -> () + }) {operand_segment_sizes = dense<[1,1,0,0,0]> : vector<5xi32>} : (i1, i32) -> () omp.terminator - }) {operand_segment_sizes = array, proc_bind_val = #omp} : (i1, i32, memref, memref) -> () + }) {operand_segment_sizes = dense<[1,1,1,1,0]> : vector<5xi32>, 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 = array} : (memref, memref) -> () + }) {operand_segment_sizes = dense<[0,0,1,1,0]> : vector<5xi32>} : (memref, memref) -> () return } @@ -141,7 +141,7 @@ 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 = array, ordered_val = 1} : + }) {operand_segment_sizes = dense<[1,1,1,0,0,0,0]> : vector<7xi32>, ordered_val = 1} : (index, index, index) -> () // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(static) @@ -149,7 +149,7 @@ func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memre "omp.wsloop" (%lb, %ub, %step, %data_var, %linear_var) ({ ^bb0(%iv: index): omp.yield - }) {operand_segment_sizes = array, schedule_val = #omp} : + }) {operand_segment_sizes = dense<[1,1,1,1,1,0,0]> : vector<7xi32>, schedule_val = #omp} : (index, index, index, memref, i32) -> () // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref, %{{.*}} = %{{.*}} : memref) schedule(static) @@ -157,7 +157,7 @@ func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memre "omp.wsloop" (%lb, %ub, %step, %data_var, %data_var, %linear_var, %linear_var) ({ ^bb0(%iv: index): omp.yield - }) {operand_segment_sizes = array, schedule_val = #omp} : + }) {operand_segment_sizes = dense<[1,1,1,2,2,0,0]> : vector<7xi32>, schedule_val = #omp} : (index, index, index, memref, memref, i32, i32) -> () // CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref) schedule(dynamic = %{{.*}}) ordered(2) @@ -165,7 +165,7 @@ func.func @omp_wsloop(%lb : index, %ub : index, %step : index, %data_var : memre "omp.wsloop" (%lb, %ub, %step, %data_var, %linear_var, %chunk_var) ({ ^bb0(%iv: index): omp.yield - }) {operand_segment_sizes = array, schedule_val = #omp, ordered_val = 2} : + }) {operand_segment_sizes = dense<[1,1,1,1,1,0,1]> : vector<7xi32>, schedule_val = #omp, ordered_val = 2} : (index, index, index, memref, i32, i32) -> () // CHECK: omp.wsloop schedule(auto) nowait @@ -173,7 +173,7 @@ 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 = array, nowait, schedule_val = #omp} : + }) {operand_segment_sizes = dense<[1,1,1,0,0,0,0]> : vector<7xi32>, nowait, schedule_val = #omp} : (index, index, index) -> () return @@ -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 = array} : - (index, index, index) -> () + }) {operand_segment_sizes = dense<[1,1,1,0]> : vector<4xi32>} : + (index, index, index) -> () return } @@ -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 = array} : ( i1, si32, i32 ) -> () + }) {nowait, operand_segment_sizes = dense<[1,1,1]>: vector<3xi32>} : ( i1, si32, i32 ) -> () // CHECK: omp.barrier omp.barrier @@ -1227,13 +1227,13 @@ func.func @omp_sectionsop(%data_var1 : memref, %data_var2 : memref, "omp.sections" (%data_var1, %data_var1) ({ // CHECK: omp.terminator omp.terminator - }) {operand_segment_sizes = array} : (memref, memref) -> () + }) {operand_segment_sizes = dense<[0,1,1]> : vector<3xi32>} : (memref, memref) -> () // CHECK: omp.sections reduction(@add_f32 -> %{{.*}} : !llvm.ptr) "omp.sections" (%redn_var) ({ // CHECK: omp.terminator omp.terminator - }) {operand_segment_sizes = array, reductions=[@add_f32]} : (!llvm.ptr) -> () + }) {operand_segment_sizes = dense<[1,0,0]> : vector<3xi32>, 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 index e93d34c..954b5d0 100644 --- a/mlir/test/Dialect/PDL/invalid.mlir +++ b/mlir/test/Dialect/PDL/invalid.mlir @@ -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 = array + operand_segment_sizes = dense<0> : vector<3xi32> } : () -> (!pdl.operation) rewrite %op with "rewriter" } @@ -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 = array + operand_segment_sizes = dense<1> : vector<3xi32> } : (!pdl.operation, !pdl.operation, !pdl.value) -> () } } @@ -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 = array + operand_segment_sizes = dense<[1,0]> : vector<2xi32> } : (!pdl.operation) -> () } @@ -272,7 +272,7 @@ pdl.pattern : benefit(1) { "pdl.rewrite"(%op, %op) ({ ^bb1: }) { - operand_segment_sizes = array + operand_segment_sizes = dense<1> : vector<2xi32> }: (!pdl.operation, !pdl.operation) -> () } @@ -286,7 +286,7 @@ pdl.pattern : benefit(1) { ^bb1: }) { name = "foo", - operand_segment_sizes = array + operand_segment_sizes = dense<[1,0]> : vector<2xi32> } : (!pdl.operation) -> () } diff --git a/mlir/test/Dialect/PDLInterp/invalid.mlir b/mlir/test/Dialect/PDLInterp/invalid.mlir index f194d32..e44625d 100644 --- a/mlir/test/Dialect/PDLInterp/invalid.mlir +++ b/mlir/test/Dialect/PDLInterp/invalid.mlir @@ -19,7 +19,8 @@ pdl_interp.func @rewriter() { inferredResultTypes, inputAttributeNames = [], name = "foo.op", - operand_segment_sizes = array + operand_segment_sizes = dense<[0, 0, 1]> : vector<3xi32> } : (!pdl.type) -> (!pdl.operation) pdl_interp.finalize } + diff --git a/mlir/test/Dialect/SCF/invalid.mlir b/mlir/test/Dialect/SCF/invalid.mlir index 86d1cb6..6fcde70 100644 --- a/mlir/test/Dialect/SCF/invalid.mlir +++ b/mlir/test/Dialect/SCF/invalid.mlir @@ -131,7 +131,7 @@ func.func @parallel_body_arguments_wrong_type( "scf.parallel"(%arg0, %arg1, %arg2) ({ ^bb0(%i0: f32): scf.yield - }) {operand_segment_sizes = array}: (index, index, index) -> () + }) {operand_segment_sizes = dense<[1, 1, 1, 0]>: vector<4xi32>}: (index, index, index) -> () return } @@ -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 = array}: (index, index, index) -> () + }) {operand_segment_sizes = dense<[1, 1, 1, 0]>: vector<4xi32>}: (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 index 1780c94..4a2c9fd 100644 --- 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_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 = array} : (i1) -> () + "spv.BranchConditional"(%true)[^one] {operand_segment_sizes = dense<[1, 0, 0]>: vector<3xi32>} : (i1) -> () ^one: spv.Return ^two: @@ -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 = array} : (i1) -> () + operand_segment_sizes = dense<[1, 0, 0]>: vector<3xi32>} : (i1) -> () ^one: spv.Return ^two: diff --git a/mlir/test/IR/parser.mlir b/mlir/test/IR/parser.mlir index ba57a91..34b667f 100644 --- a/mlir/test/IR/parser.mlir +++ b/mlir/test/IR/parser.mlir @@ -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 = array} : (i1, i17, i1, i17) -> () + "cf.cond_br"(%x, %y, %x, %y) [^bb2, ^bb3] {operand_segment_sizes = dense<[1, 1, 2]>: vector<3xi32>} : (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 index 80e0d4c..b5846d1 100644 --- a/mlir/test/IR/traits.mlir +++ b/mlir/test/IR/traits.mlir @@ -375,101 +375,114 @@ func.func private @foo() // ----- func.func @failedMissingOperandSizeAttr(%arg: i32) { - // expected-error @+1 {{requires dense i32 array attribute 'operand_segment_sizes'}} + // expected-error @+1 {{requires 1D i32 elements 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 dense i32 array attribute 'operand_segment_sizes'}} + // expected-error @+1 {{requires 1D i32 elements 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 dense i32 array attribute 'operand_segment_sizes'}} - "test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = array} : (i32, i32, i32, 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) -> () } // ----- 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 = array} : (i32, i32, i32, i32) -> () + "test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[1, 1, -1, 1]>: vector<4xi32>} : (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 = array} : (i32, i32, i32, i32) -> () + "test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[0, 1, 1, 1]>: vector<4xi32>} : (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 = array} : (i32, i32, i32, i32) -> () + "test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[2, 1, 1]>: vector<3xi32>} : (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 = array} : (i32, i32, i32, i32) -> () + "test.attr_sized_operands"(%arg, %arg, %arg, %arg) {operand_segment_sizes = dense<[0, 2, 1, 1]>: vector<4xi32>} : (i32, i32, i32, i32) -> () return } // ----- func.func @failedMissingResultSizeAttr() { - // expected-error @+1 {{requires dense i32 array attribute 'result_segment_sizes'}} + // expected-error @+1 {{requires 1D i32 elements attribute 'result_segment_sizes'}} %0:4 = "test.attr_sized_results"() : () -> (i32, i32, i32, i32) } // ----- func.func @failedResultSizeAttrWrongType() { - // expected-error @+1 {{requires dense i32 array attribute 'result_segment_sizes'}} + // expected-error @+1 {{requires 1D i32 elements 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 dense i32 array attribute 'result_segment_sizes'}} - %0:4 = "test.attr_sized_results"() {result_segment_sizes = array} : () -> (i32, i32, i32, i32) + // 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) } // ----- func.func @failedResultSizeAttrNegativeValue() { // expected-error @+1 {{'result_segment_sizes' attribute cannot have negative elements}} - %0:4 = "test.attr_sized_results"() {result_segment_sizes = array} : () -> (i32, i32, i32, i32) + %0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[1, 1, -1, 1]>: vector<4xi32>} : () -> (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 = array} : () -> (i32, i32, i32, i32) + %0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[0, 1, 1, 1]>: vector<4xi32>} : () -> (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 = array} : () -> (i32, i32, i32, i32) + %0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[2, 1, 1]>: vector<3xi32>} : () -> (i32, i32, i32, i32) } // ----- func.func @succeededResultSizeAttr() { // CHECK: test.attr_sized_results - %0:4 = "test.attr_sized_results"() {result_segment_sizes = array} : () -> (i32, i32, i32, i32) + %0:4 = "test.attr_sized_results"() {result_segment_sizes = dense<[0, 2, 1, 1]>: vector<4xi32>} : () -> (i32, i32, i32, i32) return } diff --git a/mlir/test/Rewrite/pdl-bytecode.mlir b/mlir/test/Rewrite/pdl-bytecode.mlir index 20e2490..aed1bbc 100644 --- a/mlir/test/Rewrite/pdl-bytecode.mlir +++ b/mlir/test/Rewrite/pdl-bytecode.mlir @@ -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 = array} : (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) -> () } // ----- @@ -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 = array} : () -> (i32, i32, i32, i32, i32) + %results:5 = "test.attr_sized_results"() {result_segment_sizes = dense<[0, 4, 1, 0]> : vector<4xi32>} : () -> (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 index 05ab821..a3e6aa2 100644 --- a/mlir/test/Target/LLVMIR/openmp-llvm.mlir +++ b/mlir/test/Target/LLVMIR/openmp-llvm.mlir @@ -379,7 +379,7 @@ llvm.func @wsloop_simple(%arg0: !llvm.ptr) { llvm.store %3, %4 : !llvm.ptr omp.yield // CHECK: call void @__kmpc_for_static_fini(ptr @[[$wsloop_loc_struct]], - }) {operand_segment_sizes = array} : (i64, i64, i64) -> () + }) {operand_segment_sizes = dense<[1, 1, 1, 0, 0, 0, 0]> : vector<7xi32>} : (i64, i64, i64) -> () omp.terminator } llvm.return @@ -399,7 +399,7 @@ llvm.func @wsloop_inclusive_1(%arg0: !llvm.ptr) { %4 = llvm.getelementptr %arg0[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr llvm.store %3, %4 : !llvm.ptr omp.yield - }) {operand_segment_sizes = array} : (i64, i64, i64) -> () + }) {operand_segment_sizes = dense<[1, 1, 1, 0, 0, 0, 0]> : vector<7xi32>} : (i64, i64, i64) -> () llvm.return } @@ -417,7 +417,7 @@ llvm.func @wsloop_inclusive_2(%arg0: !llvm.ptr) { %4 = llvm.getelementptr %arg0[%arg1] : (!llvm.ptr, i64) -> !llvm.ptr llvm.store %3, %4 : !llvm.ptr omp.yield - }) {inclusive, operand_segment_sizes = array} : (i64, i64, i64) -> () + }) {inclusive, operand_segment_sizes = dense<[1, 1, 1, 0, 0, 0, 0]> : vector<7xi32>} : (i64, i64, i64) -> () llvm.return } @@ -697,8 +697,8 @@ llvm.func @simdloop_simple(%lb : i64, %ub : i64, %step : i64, %arg0: !llvm.ptr, i64) -> !llvm.ptr llvm.store %3, %4 : !llvm.ptr omp.yield - }) {operand_segment_sizes = array} : - (i64, i64, i64) -> () + }) {operand_segment_sizes = dense<[1,1,1,0]> : vector<4xi32>} : + (i64, i64, i64) -> () llvm.return } @@ -720,7 +720,7 @@ llvm.func @simdloop_simple_multiple(%lb1 : i64, %ub1 : i64, %step1 : i64, %lb2 : 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 @@ llvm.func @simdloop_simple_multiple_simdlen(%lb1 : i64, %ub1 : i64, %step1 : i64 // 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 = array} : (i64) -> !llvm.ptr + %1 = llvm.alloca %0 x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>} : (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 = array, uniq_name = "_QFtest_simdEi"} : (i64) -> !llvm.ptr + %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 %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 index 3a19cac..4c5cd75 100644 --- a/mlir/test/Transforms/canonicalize-block-merge.mlir +++ b/mlir/test/Transforms/canonicalize-block-merge.mlir @@ -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 = array + operand_segment_sizes = dense<0> : vector<2 x i32> } : () -> i32 ^bb1: diff --git a/mlir/test/Transforms/sccp.mlir b/mlir/test/Transforms/sccp.mlir index 2c7f571..490809f 100644 --- a/mlir/test/Transforms/sccp.mlir +++ b/mlir/test/Transforms/sccp.mlir @@ -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 = array + operand_segment_sizes = dense<[0, 1]> : vector<2 x i32> } : (i32) -> () ^bb1: @@ -231,3 +231,4 @@ func.func @inplace_fold(%arg: i1) -> (i32) { ^b: return %1 : i32 } + diff --git a/mlir/test/lib/Dialect/Test/TestOps.td b/mlir/test/lib/Dialect/Test/TestOps.td index 377e902..b500a54 100644 --- a/mlir/test/lib/Dialect/Test/TestOps.td +++ b/mlir/test/lib/Dialect/Test/TestOps.td @@ -716,14 +716,14 @@ def AttrSizedOperandOp : TEST_Op<"attr_sized_operands", Variadic:$b, I32:$c, Variadic:$d, - DenseI32ArrayAttr:$operand_segment_sizes + I32ElementsAttr:$operand_segment_sizes ); } def AttrSizedResultOp : TEST_Op<"attr_sized_results", [AttrSizedResultSegments]> { let arguments = (ins - DenseI32ArrayAttr:$result_segment_sizes + I32ElementsAttr:$result_segment_sizes ); let results = (outs Variadic:$a, @@ -2056,7 +2056,7 @@ def FormatVariadicOfVariadicOperand : TEST_Op<"format_variadic_of_variadic_operand"> { let arguments = (ins VariadicOfVariadic:$operand, - DenseI32ArrayAttr:$operand_segments + I32ElementsAttr:$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 index fbb0552..f11c059 100644 --- a/mlir/test/python/dialects/linalg/ops.py +++ b/mlir/test/python/dialects/linalg/ops.py @@ -1,8 +1,12 @@ # RUN: %PYTHON %s | FileCheck %s -from mlir.dialects import arith, builtin, func, linalg -from mlir.dialects.linalg.opdsl.lang import * 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.linalg.opdsl.lang import * def run(f): @@ -134,7 +138,7 @@ def testNamedStructuredOpGenericForm(): # CHECK-NEXT: arith.addf{{.*}} (f32, f32) -> f32 # CHECK-NEXT: linalg.yield{{.*}} (f32) -> () # CHECK-NEXT: cast = #linalg.type_fn - # CHECK-SAME: operand_segment_sizes = array + # CHECK-SAME: operand_segment_sizes = dense<[2, 1]> : vector<2xi32> # 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 index f09d730..5aa9bef 100644 --- a/mlir/test/python/dialects/ods_helpers.py +++ b/mlir/test/python/dialects/ods_helpers.py @@ -1,10 +1,8 @@ # RUN: %PYTHON %s | FileCheck %s import gc - from mlir.ir import * - def run(f): print("\nTEST:", f.__name__) f() @@ -127,8 +125,8 @@ def testOdsBuildDefaultSizedVariadic(): # CHECK: %[[V2:.+]] = "custom.value" # CHECK: %[[V3:.+]] = "custom.value" # CHECK: "custom.test_op"(%[[V0]], %[[V1]], %[[V2]], %[[V3]]) - # CHECK-SAME: operand_segment_sizes = array - # CHECK-SAME: result_segment_sizes = array>] + # CHECK-SAME: operand_segment_sizes = dense<[1, 2, 1]> : vector<3xi32> + # CHECK-SAME: result_segment_sizes = dense<[2, 1, 1]> : vector<3xi32> # 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 index 1efe6af..0b03c76 100644 --- a/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp +++ b/mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp @@ -94,23 +94,27 @@ 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(); + if (sizeAttr.isSplat()) + return {*sizeAttrValueIt * index, *sizeAttrValueIt}; + unsigned start = 0; for (unsigned i = 0; i < index; ++i) - start += sizeAttr[i]; - return {start, sizeAttr[index]}; + start += sizeAttrValueIt[i]; + return {start, sizeAttrValueIt[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::DenseI32ArrayAttr>(); + auto sizeAttr = {0}.cast<::mlir::DenseIntElementsAttr>(); )"; /// 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::DenseI32ArrayAttr>(); + auto sizeAttr = {0}.cast<::mlir::DenseIntElementsAttr>(); )"; /// The logic to calculate the actual value range for a declared operand @@ -120,12 +124,13 @@ static const char *const opSegmentSizeAttrInitCode = R"( /// {1}: The index of the main operand. static const char *const variadicOfVariadicAdaptorCalcCode = R"( auto tblgenTmpOperands = getODSOperands({1}); - auto sizes = {0}(); + auto sizeAttrValues = {0}().getValues(); + auto sizeAttrIt = sizeAttrValues.begin(); ::llvm::SmallVector<::mlir::ValueRange> tblgenTmpOperandGroups; - for (int i = 0, e = sizes.size(); i < e; ++i) {{ - tblgenTmpOperandGroups.push_back(tblgenTmpOperands.take_front(sizes[i])); - tblgenTmpOperands = tblgenTmpOperands.drop_front(sizes[i]); + for (int i = 0, e = ::llvm::size(sizeAttrValues); i < e; ++i, ++sizeAttrIt) {{ + tblgenTmpOperandGroups.push_back(tblgenTmpOperands.take_front(*sizeAttrIt)); + tblgenTmpOperands = tblgenTmpOperands.drop_front(*sizeAttrIt); } return tblgenTmpOperandGroups; )"; @@ -603,8 +608,9 @@ static void genNativeTraitAttrVerifier(MethodBody &body, // {3}: Emit error prefix. const char *const checkAttrSizedValueSegmentsCode = R"( { - auto sizeAttr = tblgen_{0}.cast<::mlir::DenseI32ArrayAttr>(); - auto numElements = sizeAttr.asArrayRef().size(); + auto sizeAttr = tblgen_{0}.cast<::mlir::DenseIntElementsAttr>(); + auto numElements = + sizeAttr.getType().cast<::mlir::ShapedType>().getNumElements(); if (numElements != {1}) return {3}"'{0}' attribute for specifying {2} segments must have {1} " "elements, but got ") << numElements; @@ -2050,7 +2056,7 @@ void OpEmitter::genCodeForAddingArgAndRegionForBuilder( << op.getGetterName( operand.constraint.getVariadicOfVariadicSegmentSizeAttr()) << "AttrName(" << builderOpState << ".name), " << odsBuilder - << ".getDenseI32ArrayAttr(rangeSegments));" + << ".getI32TensorAttr(rangeSegments));" << " }\n"; continue; } @@ -2065,7 +2071,7 @@ void OpEmitter::genCodeForAddingArgAndRegionForBuilder( std::string sizes = op.getGetterName(operandSegmentAttrName); body << " " << builderOpState << ".addAttribute(" << sizes << "AttrName(" << builderOpState << ".name), " - << "odsBuilder.getDenseI32ArrayAttr({"; + << "odsBuilder.getI32VectorAttr({"; 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 index 55a4a8f..f52d14d 100644 --- a/mlir/tools/mlir-tblgen/OpFormatGen.cpp +++ b/mlir/tools/mlir-tblgen/OpFormatGen.cpp @@ -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().getDenseI32ArrayAttr({"; + << "parser.getBuilder().getI32VectorAttr({"; auto interleaveFn = [&](const NamedTypeConstraint &operand) { // If the operand is variadic emit the parsed size. if (operand.isVariableLength()) @@ -1574,7 +1574,7 @@ void OperationFormat::genParserVariadicSegmentResolution(Operator &op, continue; body << llvm::formatv( " result.addAttribute(\"{0}\", " - "parser.getBuilder().getDenseI32ArrayAttr({1}OperandGroupSizes));\n", + "parser.getBuilder().getI32TensorAttr({1}OperandGroupSizes));\n", operand.constraint.getVariadicOfVariadicSegmentSizeAttr(), operand.name); } @@ -1583,7 +1583,7 @@ void OperationFormat::genParserVariadicSegmentResolution(Operator &op, if (!allResultTypes && op.getTrait("::mlir::OpTrait::AttrSizedResultSegments")) { body << " result.addAttribute(\"result_segment_sizes\", " - << "parser.getBuilder().getDenseI32ArrayAttr({"; + << "parser.getBuilder().getI32VectorAttr({"; auto interleaveFn = [&](const NamedTypeConstraint &result) { // If the result is variadic emit the parsed size. if (result.isVariableLength()) -- 2.7.4