MLIR  19.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 
36 SmallVector<int64_t> getUnPackInverseSrcPerm(tensor::UnPackOp unpackOp);
37 
39  PackingMetadata &metadata);
40 
41 /// A tensor.insert_slice is a cast-like operation if it merely rank-extends the
42 /// source tensor or inserts the source tensor into a destination tensor with
43 /// the same shape.
44 bool isCastLikeInsertSliceOp(InsertSliceOp op);
45 
46 /// A tensor.extract_slice is a cast-like operation if it merely rank-reduces
47 /// unit dimensions of the source tensor or extracts the entire source tensor.
48 bool isCastLikeExtractSliceOp(ExtractSliceOp op);
49 
50 } // namespace tensor
51 } // namespace mlir
52 
53 #endif // MLIR_DIALECT_TENSOR_UTILS_UTILS_H_
SmallVector< int64_t > getUnPackInverseSrcPerm(tensor::UnPackOp 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:142
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:162
SmallVector< int64_t > getPackInverseDestPerm(tensor::PackOp packOp)
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.