forked from OSchip/llvm-project
[mlir][Shape] Lower cstr_eq to shape_eq + assert
Differential Revision: https://reviews.llvm.org/D97860
This commit is contained in:
parent
19aefd2d5d
commit
73cb58dc48
|
@ -39,6 +39,7 @@ public:
|
|||
void mlir::populateConvertShapeConstraintsConversionPatterns(
|
||||
OwningRewritePatternList &patterns, MLIRContext *ctx) {
|
||||
patterns.insert<CstrBroadcastableToRequire>(ctx);
|
||||
patterns.insert<CstrEqToRequire>(ctx);
|
||||
patterns.insert<ConvertCstrRequireOp>(ctx);
|
||||
}
|
||||
|
||||
|
|
|
@ -24,4 +24,11 @@ def CstrBroadcastableToRequire : Pat<(Shape_CstrBroadcastableOp $shapes),
|
|||
(Shape_IsBroadcastableOp $shapes),
|
||||
(BroadcastableStringAttr))>;
|
||||
|
||||
def EqStringAttr : NativeCodeCall<[{
|
||||
$_builder.getStringAttr("required equal shapes")
|
||||
}]>;
|
||||
|
||||
def CstrEqToRequire : Pat<(Shape_CstrEqOp $shapes),
|
||||
(Shape_CstrRequireOp (Shape_ShapeEqOp $shapes), (EqStringAttr))>;
|
||||
|
||||
#endif // MLIR_CONVERSION_SHAPETOSTANDARD_TD
|
||||
|
|
|
@ -14,6 +14,19 @@ func @cstr_broadcastable(%arg0: tensor<?xindex>, %arg1: tensor<?xindex>) -> !sha
|
|||
return %witness : !shape.witness
|
||||
}
|
||||
|
||||
// CHECK-LABEL: func @cstr_eq(
|
||||
// CHECK-SAME: %[[LHS:.*]]: tensor<?xindex>,
|
||||
// CHECK-SAME: %[[RHS:.*]]: tensor<?xindex>) -> !shape.witness {
|
||||
// CHECK: %[[RET:.*]] = shape.const_witness true
|
||||
// CHECK: %[[EQUAL_IS_VALID:.*]] = shape.shape_eq %[[LHS]], %[[RHS]]
|
||||
// CHECK: assert %[[EQUAL_IS_VALID]], "required equal shapes"
|
||||
// CHECK: return %[[RET]] : !shape.witness
|
||||
// CHECK: }
|
||||
func @cstr_eq(%arg0: tensor<?xindex>, %arg1: tensor<?xindex>) -> !shape.witness {
|
||||
%witness = shape.cstr_eq %arg0, %arg1 : tensor<?xindex>, tensor<?xindex>
|
||||
return %witness : !shape.witness
|
||||
}
|
||||
|
||||
// CHECK-LABEL: func @cstr_require
|
||||
func @cstr_require(%arg0: i1) -> !shape.witness {
|
||||
// CHECK: %[[RET:.*]] = shape.const_witness true
|
||||
|
|
Loading…
Reference in New Issue