MLIR  20.0.0git
Utils.h
Go to the documentation of this file.
1 //===- Utils.h - Utilities to support the Tensor dialect -------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 #ifndef MLIR_DIALECT_TENSOR_UTILS_UTILS_H_
10 #define MLIR_DIALECT_TENSOR_UTILS_UTILS_H_
11 
13 
14 namespace mlir {
15 namespace tensor {
16 
17 // Return a PadOp that pads `source` to `type` size where the static
18 // sizes are assumed to be greater than the dynamic sizes. If `type` has dynamic
19 // dimensions the padding width is set to zero. The op performs "high" padding
20 // (i.e. it adds trailing padding values until the desired size is met).
21 PadOp createPadHighOp(RankedTensorType type, Value source, Value pad,
22  bool nofold, Location loc, OpBuilder &builder);
23 
24 // Creates dim ops for each dynamic dimension of the ranked tensor argument and
25 // returns these as values.
26 SmallVector<Value> createDynamicDimValues(OpBuilder &b, Location loc,
27  Value rankedTensor);
28 
29 /// Returns the transposed `rankedTensorType` if `transposeVector` is non-empty.
30 /// Fail if `transposeVector` is not a permutation matching the tensor rank.
31 FailureOr<RankedTensorType>
32 computeTransposedType(RankedTensorType rankedTensorType,
33  ArrayRef<int64_t> transposeVector);
34 
35 /// Shell function to compute the Destination Permutation of PackOp
36 /// This function uses the helper function `computePackUnPackPerm` to get
37 /// the permutation vector. Only major difference between UnPack and Pack is
38 /// that packOp uses destination rank whereas unpack Uses source rank.
40 
41 /// Shell function to compute the Source Permutation of unPackOp.
42 /// This function, like the getPackInverseDestPerm uses the helper function
43 /// computePackUnPackPerm` to get the permutation vector.
44 /// Only major difference between UnPack and Pack is that packOp uses
45 /// destination rank whereas unpack Uses source rank.
46 SmallVector<int64_t> getUnPackInverseSrcPerm(tensor::UnPackOp unpackOp);
47 
48 /// Shell function to compute the Source rank permutation for unpackOp
49 /// Unpack requires some packing metadata data information, so created
50 /// another function where this value is passed by reference.
52  PackingMetadata &metadata);
53 
54 /// A tensor.insert_slice is a cast-like operation if it merely rank-extends the
55 /// source tensor or inserts the source tensor into a destination tensor with
56 /// the same shape.
57 bool isCastLikeInsertSliceOp(InsertSliceOp op);
58 
59 /// A tensor.extract_slice is a cast-like operation if it merely rank-reduces
60 /// unit dimensions of the source tensor or extracts the entire source tensor.
61 bool isCastLikeExtractSliceOp(ExtractSliceOp op);
62 
63 } // namespace tensor
64 } // namespace mlir
65 
66 #endif // MLIR_DIALECT_TENSOR_UTILS_UTILS_H_
SmallVector< int64_t > getUnPackInverseSrcPerm(tensor::UnPackOp unpackOp)
Shell function to compute the Source Permutation of unPackOp.
SmallVector< Value > createDynamicDimValues(OpBuilder &b, Location loc, Value rankedTensor)
Definition: Utils.cpp:43
bool isCastLikeInsertSliceOp(InsertSliceOp op)
A tensor.insert_slice is a cast-like operation if it merely rank-extends the source tensor or inserts...
Definition: Utils.cpp:131
bool isCastLikeExtractSliceOp(ExtractSliceOp op)
A tensor.extract_slice is a cast-like operation if it merely rank-reduces unit dimensions of the sour...
Definition: Utils.cpp:155
SmallVector< int64_t > getPackInverseDestPerm(tensor::PackOp packOp)
Shell function to compute the Destination Permutation of PackOp This function uses the helper functio...
PadOp createPadHighOp(RankedTensorType type, Value source, Value pad, bool nofold, Location loc, OpBuilder &builder)
Definition: Utils.cpp:24
FailureOr< RankedTensorType > computeTransposedType(RankedTensorType rankedTensorType, ArrayRef< int64_t > transposeVector)
Returns the transposed rankedTensorType if transposeVector is non-empty.
Definition: Utils.cpp:57
Include the generated interface declarations.