Skip to content

[mlir][vector] Add build method for vector.to_elements #145114

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions mlir/include/mlir/Dialect/Vector/IR/VectorOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ def Vector_ToElementsOp : Vector_Op<"to_elements", [
This operation decomposes all the scalar elements from a vector. The
decomposed scalar elements are returned in row-major order. The number of
scalar results must match the number of elements in the input vector type.
All the result elements have the same result type, which must match the
All the result elements have the same type, which must match the
element type of the input vector. Scalable vectors are not supported.

Examples:
Expand All @@ -813,7 +813,7 @@ def Vector_ToElementsOp : Vector_Op<"to_elements", [
// %0#0 = %v1[0]
// %0#1 = %v1[1]

// Decompose a 2-D.
// Decompose a 2-D vector.
%0:6 = vector.to_elements %v2 : vector<2x3xf32>
// %0#0 = %v2[0, 0]
// %0#1 = %v2[0, 1]
Expand All @@ -835,6 +835,13 @@ def Vector_ToElementsOp : Vector_Op<"to_elements", [

let arguments = (ins AnyVectorOfAnyRank:$source);
let results = (outs Variadic<AnyType>:$elements);


let builders = [
// Build method that infers the result types from `elements`.
OpBuilder<(ins "Value":$elements)>,
];

let assemblyFormat = "$source attr-dict `:` type($source)";
let hasFolder = 1;
}
Expand Down
9 changes: 9 additions & 0 deletions mlir/lib/Dialect/Vector/IR/VectorOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2417,6 +2417,15 @@ LogicalResult ToElementsOp::fold(FoldAdaptor adaptor,
return foldToElementsFromElements(*this, results);
}

void vector::ToElementsOp::build(OpBuilder &builder, OperationState &result,
Value elements) {
auto vectorType = cast<VectorType>(elements.getType());
Type elementType = vectorType.getElementType();
int64_t nbElements = vectorType.getNumElements();
SmallVector<Type> scalarTypes(nbElements, elementType);
build(builder, result, scalarTypes, elements);
}

//===----------------------------------------------------------------------===//
// FromElementsOp
//===----------------------------------------------------------------------===//
Expand Down
Loading