This corresponds with the previous work to make shape.broadcast nary. Additionally, simplify the ConvertShapeConstraints pass. It now doesn't lower an implicit shape.is_broadcastable. This is still the same in combination with shape-to-standard when the 2 passes are used in either order. Differential Revision: https://reviews.llvm.org/D96401
41 lines
1.3 KiB
TableGen
41 lines
1.3 KiB
TableGen
include "mlir/Dialect/Shape/IR/ShapeOps.td"
|
|
include "mlir/Dialect/StandardOps/IR/Ops.td"
|
|
include "mlir/Dialect/Tensor/IR/TensorOps.td"
|
|
|
|
def AllInputShapesEq : Constraint<CPred< [{
|
|
llvm::all_of($0, [&](mlir::Value val) {
|
|
return $0[0] == val;
|
|
})
|
|
}]>>;
|
|
|
|
def HasSingleElement : Constraint<CPred< [{
|
|
$0.size() == 1
|
|
}]>>;
|
|
|
|
// Canonicalization patterns.
|
|
|
|
def AssumingAllOneOp : Pat<(Shape_AssumingAllOp $args),
|
|
(replaceWithValue $args),
|
|
[(HasSingleElement $args)]>;
|
|
|
|
def CstrBroadcastableEqOps : Pat<(Shape_CstrBroadcastableOp:$op $shapes),
|
|
(Shape_ConstWitnessOp ConstBoolAttrTrue),
|
|
[(AllInputShapesEq $shapes)]>;
|
|
|
|
def CstrEqEqOps : Pat<(Shape_CstrEqOp:$op $shapes),
|
|
(Shape_ConstWitnessOp ConstBoolAttrTrue),
|
|
[(AllInputShapesEq $shapes)]>;
|
|
|
|
def IndexToSizeToIndexCanonicalization : Pat<
|
|
(Shape_SizeToIndexOp (Shape_IndexToSizeOp $arg)),
|
|
(replaceWithValue $arg)>;
|
|
|
|
def SizeToIndexToSizeCanonicalization : Pat<
|
|
(Shape_IndexToSizeOp (Shape_SizeToIndexOp $arg)),
|
|
(replaceWithValue $arg)>;
|
|
|
|
// Fold tensor.cast(const_shape) to const_shape. This changes the type of
|
|
// const_shape to the destination type of the cast.
|
|
def TensorCastConstShape : Pat <
|
|
(Tensor_CastOp (Shape_ConstShapeOp $arg)), (Shape_ConstShapeOp $arg)>;
|