@@ -742,13 +742,65 @@ mlir::LogicalResult tosa::ReshapeOp::verify() {
742
742
ShapedType outputType = getType ().cast <ShapedType>();
743
743
744
744
if (inputType.hasStaticShape () && outputType.hasStaticShape ()) {
745
+ if (getNewShape () != outputType.getShape ()) {
746
+ return emitOpError () << " newShape attribute " << getNewShape ()
747
+ << " does not match output type "
748
+ << outputType.getShape ();
749
+ }
750
+
745
751
int64_t inputElementsNum = inputType.getNumElements ();
746
752
int64_t outputElementsNum = outputType.getNumElements ();
747
753
if (inputElementsNum != outputElementsNum) {
748
754
return emitOpError () << " Cannot reshape " << inputElementsNum
749
755
<< " elements into " << outputElementsNum;
750
756
}
751
757
}
758
+
759
+ return mlir::success ();
760
+ }
761
+
762
+ mlir::LogicalResult tosa::SliceOp::verify () {
763
+ // TODO: Complete verification
764
+ ShapedType inputType = getInput ().getType ().cast <ShapedType>();
765
+ ShapedType outputType = getType ().cast <ShapedType>();
766
+
767
+ if (inputType.getRank () != outputType.getRank ()) {
768
+ return emitOpError () << " rank of input (" << inputType.getRank ()
769
+ << " ) and output ("
770
+ << outputType.getRank ()
771
+ << " ) must match" ;
772
+ }
773
+
774
+ if (getSize () != outputType.getShape ()) {
775
+ return emitOpError () << " size attribute " << getSize ()
776
+ << " does not match output type "
777
+ << outputType.getShape ();
778
+ }
779
+
780
+ if ((int64_t )getStart ().size () != inputType.getRank ()) {
781
+ return emitOpError () << " rank of start (" << getStart ().size ()
782
+ << " ) and input ("
783
+ << inputType.getRank ()
784
+ << " ) must match" ;
785
+ }
786
+ if ((int64_t )getSize ().size () != inputType.getRank ()) {
787
+ return emitOpError () << " rank of size (" << getSize ().size ()
788
+ << " ) and input ("
789
+ << inputType.getRank ()
790
+ << " ) must match" ;
791
+ }
792
+
793
+ for (int i = 0 ; i < outputType.getRank (); ++i) {
794
+ auto dimSize = inputType.getShape ()[i];
795
+ if (dimSize != ShapedType::kDynamic && getStart ()[i] + getSize ()[i] > inputType.getShape ()[i]) {
796
+ return emitOpError () << " start (" << getStart ()[i]
797
+ << " ) plus size ("
798
+ << getSize ()[i]
799
+ << " ) goes out of bounds of input size ("
800
+ << inputType.getShape ()[i]
801
+ << " ) in dimension " << i;
802
+ }
803
+ }
752
804
return mlir::success ();
753
805
}
754
806
0 commit comments