Revert "[mlir] Switch segment size attributes to DenseI32ArrayAttr"

This reverts commit 30171e76f0.

Breaks Python tests in MLIR, missing C API and Python changes.
This commit is contained in:
Alex Zinenko 2022-08-12 10:17:48 +02:00
parent e6db064394
commit e8e718fa4b
45 changed files with 272 additions and 244 deletions

View File

@ -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<T>` since it is a possible from transformations.
let hasVerifier = 0;
}
@ -538,9 +538,9 @@ class fir_IntegralSwitchTerminatorOp<string mnemonic,
}
}
$_state.addAttribute(getOperandSegmentSizeAttr(),
$_builder.getDenseI32ArrayAttr({1, 0, sumArgs}));
$_builder.getI32VectorAttr({1, 0, sumArgs}));
$_state.addAttribute(getTargetOffsetAttr(),
$_builder.getDenseI32ArrayAttr(argOffs));
$_builder.getI32VectorAttr(argOffs));
$_state.addAttributes(attributes);
}]
>];

View File

@ -113,7 +113,7 @@ createRegionOp(fir::FirOpBuilder &builder, mlir::Location loc,
builder.create<Terminator>(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<mlir::Type> argTy;
Op op = builder.create<Op>(loc, argTy, operands);
op->setAttr(Op::getOperandSegmentSizeAttr(),
builder.getDenseI32ArrayAttr(operandSegments));
builder.getI32VectorAttr(operandSegments));
return op;
}

View File

@ -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 <typename A, typename... AdditionalArgs>
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>(additionalArgs)...);
}
@ -2498,10 +2498,14 @@ getMutableSuccessorOperands(unsigned pos, mlir::MutableOperandRange operands,
*owner->getAttrDictionary().getNamed(offsetAttr);
return getSubOperands(
pos, operands,
targetOffsetAttr.getValue().cast<mlir::DenseI32ArrayAttr>(),
targetOffsetAttr.getValue().cast<mlir::DenseIntElementsAttr>(),
mlir::MutableOperandRange::OperandSegment(pos, targetOffsetAttr));
}
static unsigned denseElementsSize(mlir::DenseIntElementsAttr attr) {
return attr.getNumElements();
}
llvm::Optional<mlir::OperandRange> fir::SelectOp::getCompareOperands(unsigned) {
return {};
}
@ -2520,8 +2524,8 @@ llvm::Optional<llvm::ArrayRef<mlir::Value>>
fir::SelectOp::getSuccessorOperands(llvm::ArrayRef<mlir::Value> operands,
unsigned oper) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(
(*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getOperandSegmentSizeAttr());
return {getSubOperands(oper, getSubOperands(2, operands, segments), a)};
}
@ -2529,16 +2533,15 @@ fir::SelectOp::getSuccessorOperands(llvm::ArrayRef<mlir::Value> operands,
llvm::Optional<mlir::ValueRange>
fir::SelectOp::getSuccessorOperands(mlir::ValueRange operands, unsigned oper) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(
(*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getOperandSegmentSizeAttr());
return {getSubOperands(oper, getSubOperands(2, operands, segments), a)};
}
unsigned fir::SelectOp::targetOffsetSize() {
return (*this)
->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr())
.size();
return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getTargetOffsetAttr()));
}
//===----------------------------------------------------------------------===//
@ -2547,17 +2550,17 @@ unsigned fir::SelectOp::targetOffsetSize() {
llvm::Optional<mlir::OperandRange>
fir::SelectCaseOp::getCompareOperands(unsigned cond) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getCompareOffsetAttr());
auto a = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getCompareOffsetAttr());
return {getSubOperands(cond, getCompareArgs(), a)};
}
llvm::Optional<llvm::ArrayRef<mlir::Value>>
fir::SelectCaseOp::getCompareOperands(llvm::ArrayRef<mlir::Value> operands,
unsigned cond) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getCompareOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(
auto a = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getCompareOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getOperandSegmentSizeAttr());
return {getSubOperands(cond, getSubOperands(1, operands, segments), a)};
}
@ -2565,9 +2568,9 @@ fir::SelectCaseOp::getCompareOperands(llvm::ArrayRef<mlir::Value> operands,
llvm::Optional<mlir::ValueRange>
fir::SelectCaseOp::getCompareOperands(mlir::ValueRange operands,
unsigned cond) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getCompareOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(
auto a = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getCompareOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getOperandSegmentSizeAttr());
return {getSubOperands(cond, getSubOperands(1, operands, segments), a)};
}
@ -2581,8 +2584,8 @@ llvm::Optional<llvm::ArrayRef<mlir::Value>>
fir::SelectCaseOp::getSuccessorOperands(llvm::ArrayRef<mlir::Value> operands,
unsigned oper) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(
(*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getOperandSegmentSizeAttr());
return {getSubOperands(oper, getSubOperands(2, operands, segments), a)};
}
@ -2591,8 +2594,8 @@ llvm::Optional<mlir::ValueRange>
fir::SelectCaseOp::getSuccessorOperands(mlir::ValueRange operands,
unsigned oper) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(
(*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
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<mlir::DenseI32ArrayAttr>(getCompareOffsetAttr())
.size();
return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getCompareOffsetAttr()));
}
unsigned fir::SelectCaseOp::targetOffsetSize() {
return (*this)
->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr())
.size();
return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
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<llvm::ArrayRef<mlir::Value>>
fir::SelectRankOp::getSuccessorOperands(llvm::ArrayRef<mlir::Value> operands,
unsigned oper) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(
(*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getOperandSegmentSizeAttr());
return {getSubOperands(oper, getSubOperands(2, operands, segments), a)};
}
@ -2866,16 +2864,15 @@ llvm::Optional<mlir::ValueRange>
fir::SelectRankOp::getSuccessorOperands(mlir::ValueRange operands,
unsigned oper) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(
(*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getOperandSegmentSizeAttr());
return {getSubOperands(oper, getSubOperands(2, operands, segments), a)};
}
unsigned fir::SelectRankOp::targetOffsetSize() {
return (*this)
->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr())
.size();
return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
getTargetOffsetAttr()));
}
//===----------------------------------------------------------------------===//
@ -2901,8 +2898,8 @@ llvm::Optional<llvm::ArrayRef<mlir::Value>>
fir::SelectTypeOp::getSuccessorOperands(llvm::ArrayRef<mlir::Value> operands,
unsigned oper) {
auto a =
(*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseI32ArrayAttr>(
(*this)->getAttrOfType<mlir::DenseIntElementsAttr>(getTargetOffsetAttr());
auto segments = (*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
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<mlir::DenseI32ArrayAttr>(getTargetOffsetAttr())
.size();
return denseElementsSize((*this)->getAttrOfType<mlir::DenseIntElementsAttr>(
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);
}

View File

@ -28,7 +28,7 @@ func.func @_QPsb1(%arg0: !fir.ref<i32> {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<i32: 0, 0>, pinned} : (i64) -> !llvm.ptr<i32>
// 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<i32>
// CHECK: %[[N:.*]] = llvm.load %[[N_REF]] : !llvm.ptr<i32>
// 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<i32> {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<i32: 0, 0>, pinned} : (i64) -> !llvm.ptr<i32>
// 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<i32>
// CHECK: %[[N:.*]] = llvm.load %[[N_REF]] : !llvm.ptr<i32>
// CHECK: omp.simdloop
// CHECK-SAME: (%[[I:.*]]) : i32 = (%[[ONE_2]]) to (%[[N]]) step (%[[ONE_2]]) {

View File

@ -1701,7 +1701,7 @@ func.func @no_reassoc(%arg0: !fir.ref<i32>) {
// CHECK-LABEL: llvm.func @no_reassoc(
// CHECK-SAME: %[[ARG0:.*]]: !llvm.ptr<i32>) {
// CHECK: %[[C1:.*]] = llvm.mlir.constant(1 : i64) : i64
// CHECK: %[[ALLOC:.*]] = llvm.alloca %[[C1]] x i32 {in_type = i32, operand_segment_sizes = array<i32: 0, 0>} : (i64) -> !llvm.ptr<i32>
// CHECK: %[[ALLOC:.*]] = llvm.alloca %[[C1]] x i32 {in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>} : (i64) -> !llvm.ptr<i32>
// CHECK: %[[LOAD:.*]] = llvm.load %[[ARG0]] : !llvm.ptr<i32>
// CHECK: llvm.store %[[LOAD]], %[[ALLOC]] : !llvm.ptr<i32>
// CHECK: llvm.return
@ -1821,7 +1821,7 @@ func.func private @_QPxb(!fir.box<!fir.array<?x?xf64>>)
// 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<?x?xf64>, operand_segment_sizes = array<i32: 0, 2>, uniq_name = "_QFsbEarr"} : (i64) -> !llvm.ptr<f64>
// CHECK: %[[ARR:.*]] = llvm.alloca %[[ARR_SIZE]] x f64 {bindc_name = "arr", in_type = !fir.array<?x?xf64>, operand_segment_sizes = dense<[0, 2]> : vector<2xi32>, uniq_name = "_QFsbEarr"} : (i64) -> !llvm.ptr<f64>
// CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<f64>, 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<!fir.array<?xi32>>)
// 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<i32: 0, 0>, uniq_name = "_QFtest_dt_sliceEv"} : (i64) -> !llvm.ptr<i32>
// 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<i32>
// 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<i32: 0, 0>, uniq_name = "_QFtest_dt_sliceEx"} : (i64) -> !llvm.ptr<array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>>>
// 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<array<20 x struct<"_QFtest_dt_sliceTt", (i32, i32)>>>
// CHECK: %[[BOX0:.*]] = llvm.mlir.undef : !llvm.struct<(ptr<i32>, 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

View File

@ -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<i32: 1, 0, 0>} : (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

View File

@ -254,7 +254,7 @@ def SwitchOp : CF_Op<"switch",
Variadic<AnyType>:$defaultOperands,
VariadicOfVariadic<AnyType, "case_operand_segments">:$caseOperands,
OptionalAttr<AnyIntElementsAttr>:$case_values,
DenseI32ArrayAttr:$case_operand_segments
I32ElementsAttr:$case_operand_segments
);
let successors = (successor
AnySuccessor:$defaultDestination,

View File

@ -915,7 +915,7 @@ def LLVM_SwitchOp : LLVM_TerminatorOp<"switch",
Variadic<AnyType>:$defaultOperands,
VariadicOfVariadic<AnyType, "case_operand_segments">:$caseOperands,
OptionalAttr<ElementsAttr>:$case_values,
DenseI32ArrayAttr:$case_operand_segments,
ElementsAttr:$case_operand_segments,
OptionalAttr<ElementsAttr>:$branch_weights
);
let successors = (successor

View File

@ -86,7 +86,7 @@ class AllocLikeOp<string mnemonic,
$_state.addOperands(dynamicSizes);
$_state.addOperands(symbolOperands);
$_state.addAttribute(getOperandSegmentSizeAttr(),
$_builder.getDenseI32ArrayAttr({
$_builder.getI32VectorAttr({
static_cast<int32_t>(dynamicSizes.size()),
static_cast<int32_t>(symbolOperands.size())}));
if (alignment)

View File

@ -417,7 +417,7 @@ def PDLInterp_CreateOperationOp
```mlir
// Create an instance of a `foo.op` operation.
%op = pdl_interp.create_operation "foo.op"(%arg0 : !pdl.value) {"attrA" = %attr0} -> (%type : !pdl.type)
// Create an instance of a `foo.op` operation that has inferred result types
// (using the InferTypeOpInterface).
%op = pdl_interp.create_operation "foo.op"(%arg0 : !pdl.value) {"attrA" = %attr0} -> <inferred>

View File

@ -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 <typename ValueRangeT>
class ValueTypeRange;
class ElementsAttr;
class TypeRangeRange;
template <typename ValueIteratorT>
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<unsigned, NamedAttribute>;
/// Construct a new mutable range from the given operand, operand start index,

View File

@ -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.

View File

@ -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<int32_t>(dynamicSizesOperands.size()),
static_cast<int32_t>(copyKeyword.succeeded())}));
return success();

View File

@ -374,15 +374,15 @@ void gpu::addAsyncDependency(Operation *op, Value token) {
return;
auto attrName =
OpTrait::AttrSizedOperandSegments<void>::getOperandSegmentSizeAttr();
auto sizeAttr = op->template getAttrOfType<DenseI32ArrayAttr>(attrName);
auto sizeAttr = op->template getAttrOfType<DenseIntElementsAttr>(attrName);
// Async dependencies is the only variadic operand.
if (!sizeAttr)
return;
SmallVector<int32_t, 8> sizes(sizeAttr.asArrayRef());
SmallVector<int32_t, 8> sizes(sizeAttr.getValues<int32_t>());
++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<int32_t>(kernelOperands.size());
result.addAttribute(getOperandSegmentSizeAttr(),
builder.getDenseI32ArrayAttr(segmentSizes));
builder.getI32VectorAttr(segmentSizes));
}
StringAttr LaunchFuncOp::getKernelModuleName() {

View File

@ -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<int32_t>(operands.size()),
static_cast<int32_t>(normalOperands.size()),
static_cast<int32_t>(unwindOperands.size())}));
result.addAttribute(
InvokeOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({static_cast<int32_t>(operands.size()),
static_cast<int32_t>(normalOperands.size()),
static_cast<int32_t>(unwindOperands.size())}));
return success();
}

View File

@ -233,9 +233,9 @@ void MmaOp::build(OpBuilder &builder, OperationState &result, Type resultType,
result.addTypes(resultType);
result.addAttribute(
MmaOp::getOperandSegmentSizeAttr(),
builder.getDenseI32ArrayAttr({static_cast<int32_t>(operandA.size()),
static_cast<int32_t>(operandB.size()),
static_cast<int32_t>(operandC.size())}));
builder.getI32VectorAttr({static_cast<int32_t>(operandA.size()),
static_cast<int32_t>(operandB.size()),
static_cast<int32_t>(operandC.size())}));
}
// <operation> :=
@ -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<int32_t>(frags[0].regs.size()),
static_cast<int32_t>(frags[1].regs.size()),
static_cast<int32_t>(frags[2].regs.size()),

View File

@ -111,8 +111,8 @@ static void buildStructuredOp(OpBuilder &b, OperationState &state,
state.addAttributes(attributes);
state.addAttribute(
"operand_segment_sizes",
b.getDenseI32ArrayAttr({static_cast<int32_t>(inputs.size()),
static_cast<int32_t>(outputs.size())}));
b.getI32VectorAttr({static_cast<int32_t>(inputs.size()),
static_cast<int32_t>(outputs.size())}));
// Create and fill the region of the structured operation.
Region &region = *state.addRegion();
@ -157,7 +157,7 @@ parseCommonStructuredOpParts(OpAsmParser &parser, OperationState &result,
return failure();
result.addAttribute("operand_segment_sizes",
parser.getBuilder().getDenseI32ArrayAttr(
parser.getBuilder().getI32VectorAttr(
{static_cast<int32_t>(inputsOperands.size()),
static_cast<int32_t>(outputsOperands.size())}));
return success();

View File

@ -361,7 +361,7 @@ ParseResult ParallelOp::parse(OpAsmParser &parser, OperationState &result) {
result.addAttribute(
ParallelOp::getOperandSegmentSizeAttr(),
builder.getDenseI32ArrayAttr(
builder.getI32VectorAttr(
{static_cast<int32_t>(async.has_value() ? 1 : 0),
static_cast<int32_t>(waitOperands.size()),
static_cast<int32_t>(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<int32_t>(gangNum.has_value() ? 1 : 0),
static_cast<int32_t>(gangStatic.has_value() ? 1 : 0),
static_cast<int32_t>(worker.has_value() ? 1 : 0),

View File

@ -2105,10 +2105,10 @@ void ParallelOp::build(
result.addOperands(initVals);
result.addAttribute(
ParallelOp::getOperandSegmentSizeAttr(),
builder.getDenseI32ArrayAttr({static_cast<int32_t>(lowerBounds.size()),
static_cast<int32_t>(upperBounds.size()),
static_cast<int32_t>(steps.size()),
static_cast<int32_t>(initVals.size())}));
builder.getI32VectorAttr({static_cast<int32_t>(lowerBounds.size()),
static_cast<int32_t>(upperBounds.size()),
static_cast<int32_t>(steps.size()),
static_cast<int32_t>(initVals.size())}));
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<int32_t>(lower.size()),
static_cast<int32_t>(upper.size()),
static_cast<int32_t>(steps.size()),
static_cast<int32_t>(initVals.size())}));
builder.getI32VectorAttr({static_cast<int32_t>(lower.size()),
static_cast<int32_t>(upper.size()),
static_cast<int32_t>(steps.size()),
static_cast<int32_t>(initVals.size())}));
// Parse attributes.
if (parser.parseOptionalAttrDict(result.attributes) ||

View File

@ -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<int32_t>(trueOperands.size()),
static_cast<int32_t>(falseOperands.size())}));
result.addAttribute(
spirv::BranchConditionalOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({1, static_cast<int32_t>(trueOperands.size()),
static_cast<int32_t>(falseOperands.size())}));
return success();
}

View File

@ -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<int32_t>(indexInfo.size()), 1,
static_cast<int32_t>(hasMask.succeeded())}));
result.addAttribute(
TransferReadOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({1, static_cast<int32_t>(indexInfo.size()), 1,
static_cast<int32_t>(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<int32_t>(indexInfo.size()),
static_cast<int32_t>(hasMask.succeeded())}));
result.addAttribute(
TransferWriteOp::getOperandSegmentSizeAttr(),
builder.getI32VectorAttr({1, 1, static_cast<int32_t>(indexInfo.size()),
static_cast<int32_t>(hasMask.succeeded())}));
return failure(shapedType.isa<RankedTensorType>() &&
parser.addTypeToList(shapedType, result.types));
}

View File

@ -987,19 +987,26 @@ LogicalResult OpTrait::impl::verifyValueSizeAttr(Operation *op,
StringRef attrName,
StringRef valueGroupName,
size_t expectedCount) {
auto sizeAttr = op->getAttrOfType<DenseI32ArrayAttr>(attrName);
auto sizeAttr = op->getAttrOfType<DenseIntElementsAttr>(attrName);
if (!sizeAttr)
return op->emitOpError("requires dense i32 array attribute '")
return op->emitOpError("requires 1D i32 elements attribute '")
<< attrName << "'";
ArrayRef<int32_t> 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<APInt>(), [](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()

View File

@ -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<DenseI32ArrayAttr>().size()) {}
operandSegments.cast<DenseElementsAttr>().size()) {}
OperandRange OperandRangeRange::join() const {
const OwnerT &owner = getBase();
ArrayRef<int32_t> sizeData = owner.second.cast<DenseI32ArrayAttr>();
auto sizeData = owner.second.cast<DenseElementsAttr>().getValues<uint32_t>();
return OperandRange(owner.first,
std::accumulate(sizeData.begin(), sizeData.end(), 0));
}
OperandRange OperandRangeRange::dereference(const OwnerT &object,
ptrdiff_t index) {
ArrayRef<int32_t> sizeData = object.second.cast<DenseI32ArrayAttr>();
auto sizeData = object.second.cast<DenseElementsAttr>().getValues<uint32_t>();
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<DenseI32ArrayAttr>();
SmallVector<int32_t, 8> segments(attr.asArrayRef());
auto attr = segment.second.getValue().cast<DenseIntElementsAttr>();
SmallVector<int32_t, 8> segments(attr.getValues<int32_t>());
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<DenseI32ArrayAttr>().size()) {}
operandSegmentAttr.getValue().cast<DenseElementsAttr>().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<DenseElementsAttr>());
}
MutableOperandRange MutableOperandRangeRange::dereference(const OwnerT &object,
ptrdiff_t index) {
ArrayRef<int32_t> sizeData =
object.second.getValue().cast<DenseI32ArrayAttr>();
auto sizeData =
object.second.getValue().cast<DenseElementsAttr>().getValues<uint32_t>();
uint32_t startIndex =
std::accumulate(sizeData.begin(), sizeData.begin() + index, 0);
return object.first.slice(

View File

@ -1713,11 +1713,11 @@ executeGetOperandsResults(RangeT values, Operation *op, unsigned index,
LLVM_DEBUG(llvm::dbgs()
<< " * Extracting values from `" << attrSizedSegments << "`\n");
auto segmentAttr = op->getAttrOfType<DenseI32ArrayAttr>(attrSizedSegments);
if (!segmentAttr || segmentAttr.asArrayRef().size() <= index)
auto segmentAttr = op->getAttrOfType<DenseElementsAttr>(attrSizedSegments);
if (!segmentAttr || segmentAttr.getNumElements() <= index)
return nullptr;
ArrayRef<int32_t> segments = segmentAttr;
auto segments = segmentAttr.getValues<int32_t>();
unsigned startIndex =
std::accumulate(segments.begin(), segments.begin() + index, 0);
values = values.slice(startIndex, *std::next(segments.begin(), index));

View File

@ -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);

View File

@ -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<i32: 2, 2, 2, 0, 0, 0, 0>} : (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

View File

@ -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<i32: 0, 1, 1, 1, 1, 1, 1, 0>} : (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<i32: 0, 1, 1, 1, 1, 1, 1, 0>} : (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<i32: 0, 1, 1, 1, 1, 1, 0, 0>}
{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<i32: 0, 1, 1, 1, 1, 1, 1, 0, 0>}
{operand_segment_sizes = dense<[0, 1, 1, 1, 1, 1, 1, 0, 0]> : vector<9xi32>}
: (index, index, index, index, index, index) -> ()
return
}

View File

@ -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<i32: 2, 1>, strides = dense<2> : tensor<2xi64>} : (tensor<?x?x?x?xf32>, tensor<?x?x?x?xf32>, tensor<?x?x?x?xf32>) -> tensor<?x?x?x?xf32>
}) {dilations = dense<1> : tensor<2xi64>, linalg.memoized_indexing_maps = [#map0, #map1, #map2], operand_segment_sizes = dense<[2, 1]> : vector<2xi32>, strides = dense<2> : tensor<2xi64>} : (tensor<?x?x?x?xf32>, tensor<?x?x?x?xf32>, tensor<?x?x?x?xf32>) -> tensor<?x?x?x?xf32>
return %0 : tensor<?x?x?x?xf32>
}
@ -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<i32: 2, 1>, strides = dense<1> : tensor<2xi64>} : (tensor<?x?x?x?xf32>, tensor<?x?x?x?x?xf32>, tensor<?x?x?x?xf32>) -> tensor<?x?x?x?xf32>
}) {dilations = dense<1> : tensor<2xi64>, linalg.memoized_indexing_maps = [#map0, #map1, #map2], operand_segment_sizes = dense<[2, 1]> : vector<2xi32>, strides = dense<1> : tensor<2xi64>} : (tensor<?x?x?x?xf32>, tensor<?x?x?x?x?xf32>, tensor<?x?x?x?xf32>) -> tensor<?x?x?x?xf32>
return %0 : tensor<?x?x?x?xf32>
}

View File

@ -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<i32: 1,1,1,0>} :
(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<i32>) -> () {
// expected-error @below {{expected equal sizes for allocate and allocator variables}}
"omp.sections" (%data_var) ({
omp.terminator
}) {operand_segment_sizes = array<i32: 0,1,0>} : (memref<i32>) -> ()
}) {operand_segment_sizes = dense<[0,1,0]> : vector<3xi32>} : (memref<i32>) -> ()
return
}
@ -995,7 +995,7 @@ func.func @omp_sections(%data_var : memref<i32>) -> () {
// expected-error @below {{expected as many reduction symbol references as reduction variables}}
"omp.sections" (%data_var) ({
omp.terminator
}) {operand_segment_sizes = array<i32: 1,0,0>} : (memref<i32>) -> ()
}) {operand_segment_sizes = dense<[1,0,0]> : vector<3xi32>} : (memref<i32>) -> ()
return
}
@ -1110,7 +1110,7 @@ func.func @omp_single(%data_var : memref<i32>) -> () {
// expected-error @below {{expected equal sizes for allocate and allocator variables}}
"omp.single" (%data_var) ({
omp.barrier
}) {operand_segment_sizes = array<i32: 1,0>} : (memref<i32>) -> ()
}) {operand_segment_sizes = dense<[1,0]> : vector<2xi32>} : (memref<i32>) -> ()
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: 2, 2, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0>} : (i32, i32, i32, i32, i32, i32, memref<i32>) -> ()
}) {operand_segment_sizes = dense<[2, 2, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0]> : vector<12xi32>} : (i32, i32, i32, i32, i32, i32, memref<i32>) -> ()
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<i32: 2, 2, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0>, reductions = [@add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>, !llvm.ptr<f32>) -> ()
}) {operand_segment_sizes = dense<[2, 2, 2, 0, 0, 0, 2, 0, 0, 0, 0, 0]> : vector<12xi32>, reductions = [@add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>, !llvm.ptr<f32>) -> ()
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<i32: 2, 2, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0>, reductions = [@add_f32, @add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>) -> ()
}) {operand_segment_sizes = dense<[2, 2, 2, 0, 0, 0, 1, 0, 0, 0, 0, 0]> : vector<12xi32>, reductions = [@add_f32, @add_f32]} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>) -> ()
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: 2, 2, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0>} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>, !llvm.ptr<f32>) -> ()
}) {in_reductions = [@add_f32], operand_segment_sizes = dense<[2, 2, 2, 0, 0, 2, 0, 0, 0, 0, 0, 0]> : vector<12xi32>} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>, !llvm.ptr<f32>) -> ()
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: 2, 2, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0>} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>) -> ()
}) {in_reductions = [@add_f32, @add_f32], operand_segment_sizes = dense<[2, 2, 2, 0, 0, 1, 0, 0, 0, 0, 0, 0]> : vector<12xi32>} : (i32, i32, i32, i32, i32, i32, !llvm.ptr<f32>) -> ()
return
}

View File

@ -59,7 +59,7 @@ func.func @omp_parallel(%data_var : memref<i32>, %if_cond : i1, %num_threads : i
// CHECK: omp.parallel num_threads(%{{.*}} : i32) allocate(%{{.*}} : memref<i32> -> %{{.*}} : memref<i32>)
"omp.parallel"(%num_threads, %data_var, %data_var) ({
omp.terminator
}) {operand_segment_sizes = array<i32: 0,1,1,1,0>} : (i32, memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = dense<[0,1,1,1,0]> : vector<5xi32>} : (i32, memref<i32>, memref<i32>) -> ()
// CHECK: omp.barrier
omp.barrier
@ -68,22 +68,22 @@ func.func @omp_parallel(%data_var : memref<i32>, %if_cond : i1, %num_threads : i
// CHECK: omp.parallel if(%{{.*}}) allocate(%{{.*}} : memref<i32> -> %{{.*}} : memref<i32>)
"omp.parallel"(%if_cond, %data_var, %data_var) ({
omp.terminator
}) {operand_segment_sizes = array<i32: 1,0,1,1,0>} : (i1, memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = dense<[1,0,1,1,0]> : vector<5xi32>} : (i1, memref<i32>, memref<i32>) -> ()
// test without allocate
// CHECK: omp.parallel if(%{{.*}}) num_threads(%{{.*}} : i32)
"omp.parallel"(%if_cond, %num_threads) ({
omp.terminator
}) {operand_segment_sizes = array<i32: 1,1,0,0,0>} : (i1, i32) -> ()
}) {operand_segment_sizes = dense<[1,1,0,0,0]> : vector<5xi32>} : (i1, i32) -> ()
omp.terminator
}) {operand_segment_sizes = array<i32: 1,1,1,1,0>, proc_bind_val = #omp<procbindkind spread>} : (i1, i32, memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = dense<[1,1,1,1,0]> : vector<5xi32>, proc_bind_val = #omp<procbindkind spread>} : (i1, i32, memref<i32>, memref<i32>) -> ()
// test with multiple parameters for single variadic argument
// CHECK: omp.parallel allocate(%{{.*}} : memref<i32> -> %{{.*}} : memref<i32>)
"omp.parallel" (%data_var, %data_var) ({
omp.terminator
}) {operand_segment_sizes = array<i32: 0,0,1,1,0>} : (memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = dense<[0,0,1,1,0]> : vector<5xi32>} : (memref<i32>, memref<i32>) -> ()
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<i32: 1,1,1,0,0,0,0>, 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<i32>) 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<i32: 1,1,1,1,1,0,0>, schedule_val = #omp<schedulekind static>} :
}) {operand_segment_sizes = dense<[1,1,1,1,1,0,0]> : vector<7xi32>, schedule_val = #omp<schedulekind static>} :
(index, index, index, memref<i32>, i32) -> ()
// CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref<i32>, %{{.*}} = %{{.*}} : memref<i32>) 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<i32: 1,1,1,2,2,0,0>, schedule_val = #omp<schedulekind static>} :
}) {operand_segment_sizes = dense<[1,1,1,2,2,0,0]> : vector<7xi32>, schedule_val = #omp<schedulekind static>} :
(index, index, index, memref<i32>, memref<i32>, i32, i32) -> ()
// CHECK: omp.wsloop linear(%{{.*}} = %{{.*}} : memref<i32>) 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<i32: 1,1,1,1,1,0,1>, schedule_val = #omp<schedulekind dynamic>, ordered_val = 2} :
}) {operand_segment_sizes = dense<[1,1,1,1,1,0,1]> : vector<7xi32>, schedule_val = #omp<schedulekind dynamic>, ordered_val = 2} :
(index, index, index, memref<i32>, 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<i32: 1,1,1,0,0,0,0>, nowait, schedule_val = #omp<schedulekind auto>} :
}) {operand_segment_sizes = dense<[1,1,1,0,0,0,0]> : vector<7xi32>, nowait, schedule_val = #omp<schedulekind auto>} :
(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<i32: 1,1,1,0>} :
(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<i32: 1,1,1>} : ( 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<i32>, %data_var2 : memref<i32>,
"omp.sections" (%data_var1, %data_var1) ({
// CHECK: omp.terminator
omp.terminator
}) {operand_segment_sizes = array<i32: 0,1,1>} : (memref<i32>, memref<i32>) -> ()
}) {operand_segment_sizes = dense<[0,1,1]> : vector<3xi32>} : (memref<i32>, memref<i32>) -> ()
// CHECK: omp.sections reduction(@add_f32 -> %{{.*}} : !llvm.ptr<f32>)
"omp.sections" (%redn_var) ({
// CHECK: omp.terminator
omp.terminator
}) {operand_segment_sizes = array<i32: 1,0,0>, reductions=[@add_f32]} : (!llvm.ptr<f32>) -> ()
}) {operand_segment_sizes = dense<[1,0,0]> : vector<3xi32>, reductions=[@add_f32]} : (!llvm.ptr<f32>) -> ()
// CHECK: omp.sections nowait {
omp.sections nowait {

View File

@ -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<i32: 0, 0, 0>
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<i32: 1, 1, 1>
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<i32: 1,0>
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<i32: 1, 1>
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<i32: 1,0>
operand_segment_sizes = dense<[1,0]> : vector<2xi32>
} : (!pdl.operation) -> ()
}

View File

@ -19,7 +19,8 @@ pdl_interp.func @rewriter() {
inferredResultTypes,
inputAttributeNames = [],
name = "foo.op",
operand_segment_sizes = array<i32: 0, 0, 1>
operand_segment_sizes = dense<[0, 0, 1]> : vector<3xi32>
} : (!pdl.type) -> (!pdl.operation)
pdl_interp.finalize
}

View File

@ -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<i32: 1, 1, 1, 0>}: (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<i32: 1, 1, 1, 0>}: (index, index, index) -> ()
}) {operand_segment_sizes = dense<[1, 1, 1, 0]>: vector<4xi32>}: (index, index, index) -> ()
return
}

View File

@ -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<i32: 1, 0, 0>} : (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<i32: 1, 0, 0>} : (i1) -> ()
operand_segment_sizes = dense<[1, 0, 0]>: vector<3xi32>} : (i1) -> ()
^one:
spv.Return
^two:

View File

@ -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<i32: 1, 1, 2>} : (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

View File

@ -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<i64: 1, 1, 1, 1>} : (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: 1, 1, -1, 1>} : (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: 0, 1, 1, 1>} : (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: 2, 1, 1>} : (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: 0, 2, 1, 1>} : (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<i64: 1, 1, 1, 1>} : () -> (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: 1, 1, -1, 1>} : () -> (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: 0, 1, 1, 1>} : () -> (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: 2, 1, 1>} : () -> (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: 0, 2, 1, 1>} : () -> (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
}

View File

@ -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: 0, 4, 1, 0>} : (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: 0, 4, 1, 0>} : () -> (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) -> ()
}

View File

@ -379,7 +379,7 @@ llvm.func @wsloop_simple(%arg0: !llvm.ptr<f32>) {
llvm.store %3, %4 : !llvm.ptr<f32>
omp.yield
// CHECK: call void @__kmpc_for_static_fini(ptr @[[$wsloop_loc_struct]],
}) {operand_segment_sizes = array<i32: 1, 1, 1, 0, 0, 0, 0>} : (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<f32>) {
%4 = llvm.getelementptr %arg0[%arg1] : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
llvm.store %3, %4 : !llvm.ptr<f32>
omp.yield
}) {operand_segment_sizes = array<i32: 1, 1, 1, 0, 0, 0, 0>} : (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<f32>) {
%4 = llvm.getelementptr %arg0[%arg1] : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
llvm.store %3, %4 : !llvm.ptr<f32>
omp.yield
}) {inclusive, operand_segment_sizes = array<i32: 1, 1, 1, 0, 0, 0, 0>} : (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<f
%4 = llvm.getelementptr %arg0[%iv] : (!llvm.ptr<f32>, i64) -> !llvm.ptr<f32>
llvm.store %3, %4 : !llvm.ptr<f32>
omp.yield
}) {operand_segment_sizes = array<i32: 1,1,1,0>} :
(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<f32>
llvm.store %3, %5 : !llvm.ptr<f32>
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<i32> {fir.bindc_name = "n"}, %arg1: !llvm.ptr<i32> {fir.bindc_name = "threshold"}) {
%0 = llvm.mlir.constant(1 : i64) : i64
%1 = llvm.alloca %0 x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = array<i32: 0, 0>} : (i64) -> !llvm.ptr<i32>
%1 = llvm.alloca %0 x i32 {adapt.valuebyref, in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>} : (i64) -> !llvm.ptr<i32>
%2 = llvm.mlir.constant(1 : i64) : i64
%3 = llvm.alloca %2 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = array<i32: 0, 0>, uniq_name = "_QFtest_simdEi"} : (i64) -> !llvm.ptr<i32>
%3 = llvm.alloca %2 x i32 {bindc_name = "i", in_type = i32, operand_segment_sizes = dense<0> : vector<2xi32>, uniq_name = "_QFtest_simdEi"} : (i64) -> !llvm.ptr<i32>
%4 = llvm.mlir.constant(0 : i32) : i32
%5 = llvm.load %arg0 : !llvm.ptr<i32>
%6 = llvm.mlir.constant(1 : i32) : i32

View File

@ -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<i32: 0, 0>
operand_segment_sizes = dense<0> : vector<2 x i32>
} : () -> i32
^bb1:

View File

@ -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<i32: 0, 1>
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
}

View File

@ -716,14 +716,14 @@ def AttrSizedOperandOp : TEST_Op<"attr_sized_operands",
Variadic<I32>:$b,
I32:$c,
Variadic<I32>:$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<I32>:$a,
@ -2056,7 +2056,7 @@ def FormatVariadicOfVariadicOperand
: TEST_Op<"format_variadic_of_variadic_operand"> {
let arguments = (ins
VariadicOfVariadic<I64, "operand_segments">:$operand,
DenseI32ArrayAttr:$operand_segments
I32ElementsAttr:$operand_segments
);
let assemblyFormat = [{ $operand `:` type($operand) attr-dict}];
}

View File

@ -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<cast_signed>
# CHECK-SAME: operand_segment_sizes = array<i32: 2, 1>
# 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])

View File

@ -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<i32: 1, 2, 1>
# CHECK-SAME: result_segment_sizes = array<i32: 2, 1, 1>>]
# 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],

View File

@ -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<uint32_t>();
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<uint32_t>();
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<int>(0, op.getNumOperands()), body, [&](int i) {
const NamedTypeConstraint &operand = op.getOperand(i);
if (!operand.isVariableLength()) {

View File

@ -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())