@@ -24,110 +24,6 @@ include "mlir/Interfaces/ViewLikeInterface.td"
2424class Linalg_Op<string mnemonic, list<Trait> traits = []> :
2525 Op<Linalg_Dialect, mnemonic, traits>;
2626
27- def Linalg_InitTensorOp : Linalg_Op<"init_tensor",
28- [NoSideEffect,
29- DeclareOpInterfaceMethods<ReifyRankedShapedTypeOpInterface>]> {
30- let summary = "operation to define a tensor of particular shape";
31-
32- let description = [{
33- `linalg.init_tensor` is an operation that defines a tensor of a particular
34- shape. The shape could be dynamic or static. The contents of the tensor are
35- unspecified and the only purpose of the op result is to materialize the
36- specified shape in IR and make it available to other transformations.
37-
38- Note: This op can be lowered to a `bufferization.alloc_tensor`, at which
39- point it turns into an explicit buffer allocation.
40- }];
41-
42- let arguments =
43- (ins Variadic<Index>:$sizes, I64ArrayAttr:$static_sizes);
44-
45- let results = (outs AnyTensor:$result);
46-
47- let assemblyFormat = [{
48- custom<DynamicIndexList>($sizes, $static_sizes,
49- "ShapedType::kDynamicSize")
50- attr-dict `:` type($result)
51- }];
52-
53- let extraClassDeclaration = [{
54- static StringRef getStaticSizesAttrStrName() {
55- return "static_sizes";
56- }
57-
58- RankedTensorType getType() {
59- return getResult().getType().cast<RankedTensorType>(); }
60-
61- // Infer the shape of the result tensor given the static shapes
62- // and element type of the result tensor.
63- static Type inferResultType(ArrayRef<int64_t> staticSizes, Type elementType,
64- Attribute encoding = {});
65-
66- // Return true if the size of the tensor is dynamic at `idx`
67- bool isDynamicSize(unsigned idx) {
68- APInt v = *(getStaticSizes().getAsValueRange<IntegerAttr>().begin() + idx);
69- return ShapedType::isDynamic(v.getSExtValue());
70- }
71-
72- // Assert that the size of the result tensor is static at `idx`
73- // and return the shape.
74- int64_t getStaticSize(unsigned idx) {
75- assert(!isDynamicSize(idx) && "expected static size");
76- APInt v = *(getStaticSizes().
77- template getAsValueRange<IntegerAttr>().begin() + idx);
78- return v.getSExtValue();
79- }
80-
81- // Return the argument position that contains the dynamic size of
82- // the tensor at dimension `idx`. Asserts that the shape is
83- // dynamic at that `idx`.
84- unsigned getIndexOfDynamicSize(unsigned idx) {
85- assert(isDynamicSize(idx) && "expected dynamic size");
86- return std::count_if(
87- getStaticSizes().getValue().begin(),
88- getStaticSizes().getValue().begin() + idx,
89- [&](Attribute attr) {
90- return ShapedType::isDynamic(attr.cast<IntegerAttr>().getInt());
91- });
92- }
93-
94- // Return both static and dynamic sizes as a list of `OpFoldResult`.
95- SmallVector<OpFoldResult> getMixedSizes();
96-
97- // Return the Value of the dynamic size of the tensor at dimension
98- // `idx`. Asserts that the shape is dynamic at that `idx.
99- Value getDynamicSize(unsigned idx) {
100- return getOperand(getIndexOfDynamicSize(idx));
101- }
102- }];
103-
104- let builders = [
105- OpBuilder<(ins "ValueRange":$shape,
106- "ArrayRef<int64_t>":$staticShape, "Type":$elementType),
107- [{
108- build($_builder, $_state,
109- InitTensorOp::inferResultType(staticShape, elementType),
110- shape, $_builder.getI64ArrayAttr(staticShape));
111- }]>,
112- OpBuilder<(ins "ValueRange":$shape, "Type":$elementType),
113- [{
114- SmallVector<int64_t, 4> staticShape(
115- shape.size(), ShapedType::kDynamicSize);
116- build($_builder, $_state, shape, staticShape, elementType);
117- }]>,
118- OpBuilder<(ins "ArrayRef<int64_t>":$staticShape, "Type":$elementType),
119- [{
120- build($_builder, $_state, ValueRange{}, staticShape, elementType);
121- }]>,
122- OpBuilder<(ins "ArrayRef<OpFoldResult>":$sizes, "Type":$elementType,
123- CArg<"ArrayRef<NamedAttribute>", "{}">:$attrs)>
124- ];
125-
126- let hasCanonicalizer = 1;
127- let hasCustomAssemblyFormat = 1;
128- let hasVerifier = 1;
129- }
130-
13127def Linalg_YieldOp : Linalg_Op<"yield", [NoSideEffect, ReturnLike, Terminator]>,
13228 Arguments<(ins Variadic<AnyType>:$values)> {
13329 let summary = "Linalg yield operation";
0 commit comments