@@ -664,90 +664,51 @@ static void printGEPIndices(OpAsmPrinter &printer, LLVM::GEPOp gepOp,
664
664
});
665
665
}
666
666
667
- namespace {
668
- // / Base class for llvm::Error related to GEP index.
669
- class GEPIndexError : public llvm ::ErrorInfo<GEPIndexError> {
670
- protected:
671
- unsigned indexPos;
672
-
673
- public:
674
- static char ID;
675
-
676
- std::error_code convertToErrorCode () const override {
677
- return llvm::inconvertibleErrorCode ();
678
- }
679
-
680
- explicit GEPIndexError (unsigned pos) : indexPos(pos) {}
681
- };
682
-
683
- // / llvm::Error for out-of-bound GEP index.
684
- struct GEPIndexOutOfBoundError
685
- : public llvm::ErrorInfo<GEPIndexOutOfBoundError, GEPIndexError> {
686
- static char ID;
687
-
688
- using ErrorInfo::ErrorInfo;
689
-
690
- void log (llvm::raw_ostream &os) const override {
691
- os << " index " << indexPos << " indexing a struct is out of bounds" ;
692
- }
693
- };
694
-
695
- // / llvm::Error for non-static GEP index indexing a struct.
696
- struct GEPStaticIndexError
697
- : public llvm::ErrorInfo<GEPStaticIndexError, GEPIndexError> {
698
- static char ID;
699
-
700
- using ErrorInfo::ErrorInfo;
701
-
702
- void log (llvm::raw_ostream &os) const override {
703
- os << " expected index " << indexPos << " indexing a struct "
704
- << " to be constant" ;
705
- }
706
- };
707
- } // end anonymous namespace
708
-
709
- char GEPIndexError::ID = 0 ;
710
- char GEPIndexOutOfBoundError::ID = 0 ;
711
- char GEPStaticIndexError::ID = 0 ;
712
-
713
- // / For the given `structIndices` and `indices`, check if they're complied
714
- // / with `baseGEPType`, especially check against LLVMStructTypes nested within.
715
- static llvm::Error verifyStructIndices (Type baseGEPType, unsigned indexPos,
716
- GEPIndicesAdaptor<ValueRange> indices) {
667
+ // / For the given `indices`, check if they comply with `baseGEPType`,
668
+ // / especially check against LLVMStructTypes nested within.
669
+ static LogicalResult
670
+ verifyStructIndices (Type baseGEPType, unsigned indexPos,
671
+ GEPIndicesAdaptor<ValueRange> indices,
672
+ function_ref<InFlightDiagnostic()> emitOpError) {
717
673
if (indexPos >= indices.size ())
718
674
// Stop searching
719
- return llvm::Error:: success ();
675
+ return success ();
720
676
721
- return llvm:: TypeSwitch<Type, llvm::Error >(baseGEPType)
722
- .Case <LLVMStructType>([&](LLVMStructType structType) -> llvm::Error {
677
+ return TypeSwitch<Type, LogicalResult >(baseGEPType)
678
+ .Case <LLVMStructType>([&](LLVMStructType structType) -> LogicalResult {
723
679
if (!indices[indexPos].is <IntegerAttr>())
724
- return llvm::make_error<GEPStaticIndexError>(indexPos);
680
+ return emitOpError () << " expected index " << indexPos
681
+ << " indexing a struct to be constant" ;
725
682
726
683
int32_t gepIndex = indices[indexPos].get <IntegerAttr>().getInt ();
727
684
ArrayRef<Type> elementTypes = structType.getBody ();
728
685
if (gepIndex < 0 ||
729
686
static_cast <size_t >(gepIndex) >= elementTypes.size ())
730
- return llvm::make_error<GEPIndexOutOfBoundError>(indexPos);
687
+ return emitOpError () << " index " << indexPos
688
+ << " indexing a struct is out of bounds" ;
731
689
732
690
// Instead of recursively going into every children types, we only
733
691
// dive into the one indexed by gepIndex.
734
692
return verifyStructIndices (elementTypes[gepIndex], indexPos + 1 ,
735
- indices);
693
+ indices, emitOpError );
736
694
})
737
695
.Case <VectorType, LLVMScalableVectorType, LLVMFixedVectorType,
738
- LLVMArrayType>([&](auto containerType) -> llvm::Error {
696
+ LLVMArrayType>([&](auto containerType) -> LogicalResult {
739
697
return verifyStructIndices (containerType.getElementType (), indexPos + 1 ,
740
- indices);
698
+ indices, emitOpError );
741
699
})
742
- .Default (
743
- [](auto otherType) -> llvm::Error { return llvm::Error::success (); });
700
+ .Default ([&](auto otherType) -> LogicalResult {
701
+ return emitOpError ()
702
+ << " type " << otherType << " cannot be indexed (index #"
703
+ << indexPos << " )" ;
704
+ });
744
705
}
745
706
746
- // / Driver function around `recordStructIndices`. Note that we always check
747
- // / from the second GEP index since the first one is always dynamic.
748
- static llvm::Error verifyStructIndices (Type baseGEPType,
749
- GEPIndicesAdaptor<ValueRange> indices ) {
750
- return verifyStructIndices (baseGEPType, /* indexPos=*/ 1 , indices);
707
+ // / Driver function around `verifyStructIndices`.
708
+ static LogicalResult
709
+ verifyStructIndices (Type baseGEPType, GEPIndicesAdaptor<ValueRange> indices ,
710
+ function_ref<InFlightDiagnostic()> emitOpError ) {
711
+ return verifyStructIndices (baseGEPType, /* indexPos=*/ 1 , indices, emitOpError );
751
712
}
752
713
753
714
LogicalResult LLVM::GEPOp::verify () {
@@ -763,11 +724,8 @@ LogicalResult LLVM::GEPOp::verify() {
763
724
return emitOpError (" expected as many dynamic indices as specified in '" )
764
725
<< getRawConstantIndicesAttrName ().getValue () << " '" ;
765
726
766
- if (llvm::Error err =
767
- verifyStructIndices (getSourceElementType (), getIndices ()))
768
- return emitOpError () << llvm::toString (std::move (err));
769
-
770
- return success ();
727
+ return verifyStructIndices (getSourceElementType (), getIndices (),
728
+ [&] { return emitOpError (); });
771
729
}
772
730
773
731
Type LLVM::GEPOp::getSourceElementType () {
0 commit comments