23
23
#include " mlir/IR/OpImplementation.h"
24
24
#include " llvm/ADT/APInt.h"
25
25
#include " llvm/ADT/TypeSwitch.h"
26
+ #include " llvm/Support/CommandLine.h"
26
27
#include < iterator>
27
28
#include < mlir/Interfaces/SideEffectInterfaces.h>
28
29
#include < optional>
29
30
#include < tuple>
30
31
32
+ static llvm::cl::opt<bool > useStrictIntrinsicVerifier (
33
+ " strict-intrinsic-verifier" , llvm::cl::init(false ),
34
+ llvm::cl::desc(" use stricter verifier for HLFIR intrinsic operations" ));
35
+
31
36
// / generic implementation of the memory side effects interface for hlfir
32
37
// / transformational intrinsic operations
33
38
static void
@@ -498,7 +503,7 @@ verifyLogicalReductionOp(LogicalReductionOp reductionOp) {
498
503
mlir::Type resultType = results[0 ];
499
504
if (mlir::isa<fir::LogicalType>(resultType)) {
500
505
// Result is of the same type as MASK
501
- if (resultType != logicalTy)
506
+ if (( resultType != logicalTy) && useStrictIntrinsicVerifier )
502
507
return reductionOp->emitOpError (
503
508
" result must have the same element type as MASK argument" );
504
509
@@ -509,7 +514,7 @@ verifyLogicalReductionOp(LogicalReductionOp reductionOp) {
509
514
if (!resultExpr.isArray ())
510
515
return reductionOp->emitOpError (" result must be an array" );
511
516
512
- if (resultExpr.getEleTy () != logicalTy)
517
+ if (( resultExpr.getEleTy () != logicalTy) && useStrictIntrinsicVerifier )
513
518
return reductionOp->emitOpError (
514
519
" result must have the same element type as MASK argument" );
515
520
@@ -585,7 +590,7 @@ mlir::LogicalResult hlfir::CountOp::verify() {
585
590
if (resultShape.size () != (maskShape.size () - 1 ))
586
591
return emitOpError (" result rank must be one less than MASK" );
587
592
} else {
588
- return emitOpError (" result must be of numerical scalar type" );
593
+ return emitOpError (" result must be of numerical array type" );
589
594
}
590
595
} else if (!hlfir::isFortranScalarNumericalType (resultType)) {
591
596
return emitOpError (" result must be of numerical scalar type" );
@@ -682,15 +687,18 @@ verifyArrayAndMaskForReductionOp(NumericalReductionOp reductionOp) {
682
687
if (!maskShape.empty ()) {
683
688
if (maskShape.size () != arrayShape.size ())
684
689
return reductionOp->emitWarning (" MASK must be conformable to ARRAY" );
685
- static_assert (fir::SequenceType::getUnknownExtent () ==
686
- hlfir::ExprType::getUnknownExtent ());
687
- constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent ();
688
- for (std::size_t i = 0 ; i < arrayShape.size (); ++i) {
689
- int64_t arrayExtent = arrayShape[i];
690
- int64_t maskExtent = maskShape[i];
691
- if ((arrayExtent != maskExtent) && (arrayExtent != unknownExtent) &&
692
- (maskExtent != unknownExtent))
693
- return reductionOp->emitWarning (" MASK must be conformable to ARRAY" );
690
+ if (useStrictIntrinsicVerifier) {
691
+ static_assert (fir::SequenceType::getUnknownExtent () ==
692
+ hlfir::ExprType::getUnknownExtent ());
693
+ constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent ();
694
+ for (std::size_t i = 0 ; i < arrayShape.size (); ++i) {
695
+ int64_t arrayExtent = arrayShape[i];
696
+ int64_t maskExtent = maskShape[i];
697
+ if ((arrayExtent != maskExtent) && (arrayExtent != unknownExtent) &&
698
+ (maskExtent != unknownExtent))
699
+ return reductionOp->emitWarning (
700
+ " MASK must be conformable to ARRAY" );
701
+ }
694
702
}
695
703
}
696
704
}
@@ -719,7 +727,7 @@ verifyNumericalReductionOp(NumericalReductionOp reductionOp) {
719
727
mlir::Type resultType = results[0 ];
720
728
if (hlfir::isFortranScalarNumericalType (resultType)) {
721
729
// Result is of the same type as ARRAY
722
- if (resultType != numTy)
730
+ if (( resultType != numTy) && useStrictIntrinsicVerifier )
723
731
return reductionOp->emitOpError (
724
732
" result must have the same element type as ARRAY argument" );
725
733
@@ -729,7 +737,7 @@ verifyNumericalReductionOp(NumericalReductionOp reductionOp) {
729
737
if (!resultExpr.isArray ())
730
738
return reductionOp->emitOpError (" result must be an array" );
731
739
732
- if (resultExpr.getEleTy () != numTy)
740
+ if (( resultExpr.getEleTy () != numTy) && useStrictIntrinsicVerifier )
733
741
return reductionOp->emitOpError (
734
742
" result must have the same element type as ARRAY argument" );
735
743
@@ -792,7 +800,7 @@ verifyCharacterReductionOp(CharacterReductionOp reductionOp) {
792
800
" result must be character" );
793
801
794
802
// Result is of the same type as ARRAY
795
- if (resultType != numTy)
803
+ if (( resultType != numTy) && useStrictIntrinsicVerifier )
796
804
return reductionOp->emitOpError (
797
805
" result must have the same element type as ARRAY argument" );
798
806
@@ -823,9 +831,8 @@ mlir::LogicalResult hlfir::MaxvalOp::verify() {
823
831
auto resultExpr = mlir::dyn_cast<hlfir::ExprType>(results[0 ]);
824
832
if (resultExpr && mlir::isa<fir::CharacterType>(resultExpr.getEleTy ())) {
825
833
return verifyCharacterReductionOp<hlfir::MaxvalOp *>(this );
826
- } else {
827
- return verifyNumericalReductionOp<hlfir::MaxvalOp *>(this );
828
834
}
835
+ return verifyNumericalReductionOp<hlfir::MaxvalOp *>(this );
829
836
}
830
837
831
838
void hlfir::MaxvalOp::getEffects (
@@ -848,9 +855,8 @@ mlir::LogicalResult hlfir::MinvalOp::verify() {
848
855
auto resultExpr = mlir::dyn_cast<hlfir::ExprType>(results[0 ]);
849
856
if (resultExpr && mlir::isa<fir::CharacterType>(resultExpr.getEleTy ())) {
850
857
return verifyCharacterReductionOp<hlfir::MinvalOp *>(this );
851
- } else {
852
- return verifyNumericalReductionOp<hlfir::MinvalOp *>(this );
853
858
}
859
+ return verifyNumericalReductionOp<hlfir::MinvalOp *>(this );
854
860
}
855
861
856
862
void hlfir::MinvalOp::getEffects (
@@ -1007,17 +1013,19 @@ mlir::LogicalResult hlfir::DotProductOp::verify() {
1007
1013
1008
1014
constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent ();
1009
1015
if ((lhsSize != unknownExtent) && (rhsSize != unknownExtent) &&
1010
- (lhsSize != rhsSize))
1016
+ (lhsSize != rhsSize) && useStrictIntrinsicVerifier )
1011
1017
return emitOpError (" both arrays must have the same size" );
1012
1018
1013
- if (mlir::isa<fir::LogicalType>(lhsEleTy) !=
1014
- mlir::isa<fir::LogicalType>(rhsEleTy))
1015
- return emitOpError (" if one array is logical, so should the other be" );
1019
+ if (useStrictIntrinsicVerifier) {
1020
+ if (mlir::isa<fir::LogicalType>(lhsEleTy) !=
1021
+ mlir::isa<fir::LogicalType>(rhsEleTy))
1022
+ return emitOpError (" if one array is logical, so should the other be" );
1016
1023
1017
- if (mlir::isa<fir::LogicalType>(lhsEleTy) !=
1018
- mlir::isa<fir::LogicalType>(resultTy))
1019
- return emitOpError (" the result type should be a logical only if the "
1020
- " argument types are logical" );
1024
+ if (mlir::isa<fir::LogicalType>(lhsEleTy) !=
1025
+ mlir::isa<fir::LogicalType>(resultTy))
1026
+ return emitOpError (" the result type should be a logical only if the "
1027
+ " argument types are logical" );
1028
+ }
1021
1029
1022
1030
if (!hlfir::isFortranScalarNumericalType (resultTy) &&
1023
1031
!mlir::isa<fir::LogicalType>(resultTy))
@@ -1067,6 +1075,9 @@ mlir::LogicalResult hlfir::MatmulOp::verify() {
1067
1075
mlir::isa<fir::LogicalType>(rhsEleTy))
1068
1076
return emitOpError (" if one array is logical, so should the other be" );
1069
1077
1078
+ if (!useStrictIntrinsicVerifier)
1079
+ return mlir::success ();
1080
+
1070
1081
int64_t lastLhsDim = lhsShape[lhsRank - 1 ];
1071
1082
int64_t firstRhsDim = rhsShape[0 ];
1072
1083
constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent ();
@@ -1179,6 +1190,9 @@ mlir::LogicalResult hlfir::TransposeOp::verify() {
1179
1190
if (rank != 2 || resultRank != 2 )
1180
1191
return emitOpError (" input and output arrays should have rank 2" );
1181
1192
1193
+ if (!useStrictIntrinsicVerifier)
1194
+ return mlir::success ();
1195
+
1182
1196
constexpr int64_t unknownExtent = fir::SequenceType::getUnknownExtent ();
1183
1197
if ((inShape[0 ] != resultShape[1 ]) && (inShape[0 ] != unknownExtent))
1184
1198
return emitOpError (" output shape does not match input array" );
@@ -1226,6 +1240,9 @@ mlir::LogicalResult hlfir::MatmulTransposeOp::verify() {
1226
1240
if ((lhsRank != 2 ) || ((rhsRank != 1 ) && (rhsRank != 2 )))
1227
1241
return emitOpError (" array must have either rank 1 or rank 2" );
1228
1242
1243
+ if (!useStrictIntrinsicVerifier)
1244
+ return mlir::success ();
1245
+
1229
1246
if (mlir::isa<fir::LogicalType>(lhsEleTy) !=
1230
1247
mlir::isa<fir::LogicalType>(rhsEleTy))
1231
1248
return emitOpError (" if one array is logical, so should the other be" );
0 commit comments