@@ -498,6 +498,7 @@ llvm::hash_code OpPassManager::hash() {
498
498
499
499
LogicalResult OpToOpPassAdaptor::run (Pass *pass, Operation *op,
500
500
AnalysisManager am, bool verifyPasses,
501
+ bool emitErrorOnFailure,
501
502
unsigned parentInitGeneration) {
502
503
std::optional<RegisteredOperationName> opInfo = op->getRegisteredInfo ();
503
504
if (!opInfo)
@@ -533,9 +534,9 @@ LogicalResult OpToOpPassAdaptor::run(Pass *pass, Operation *op,
533
534
if (failed (pipeline.initialize (root->getContext (), parentInitGeneration)))
534
535
return failure ();
535
536
AnalysisManager nestedAm = root == op ? am : am.nest (root);
536
- return OpToOpPassAdaptor::runPipeline (pipeline, root, nestedAm,
537
- verifyPasses, parentInitGeneration ,
538
- pi, &parentInfo);
537
+ return OpToOpPassAdaptor::runPipeline (
538
+ pipeline, root, nestedAm, verifyPasses, emitErrorOnFailure ,
539
+ parentInitGeneration, pi, &parentInfo);
539
540
};
540
541
pass->passState .emplace (op, am, dynamicPipelineCallback);
541
542
@@ -548,7 +549,7 @@ LogicalResult OpToOpPassAdaptor::run(Pass *pass, Operation *op,
548
549
[&]() {
549
550
// Invoke the virtual runOnOperation method.
550
551
if (auto *adaptor = dyn_cast<OpToOpPassAdaptor>(pass))
551
- adaptor->runOnOperation (verifyPasses);
552
+ adaptor->runOnOperation (verifyPasses, emitErrorOnFailure );
552
553
else
553
554
pass->runOnOperation ();
554
555
passFailed = pass->passState ->irAndPassFailed .getInt ();
@@ -597,7 +598,8 @@ LogicalResult OpToOpPassAdaptor::run(Pass *pass, Operation *op,
597
598
// / Run the given operation and analysis manager on a provided op pass manager.
598
599
LogicalResult OpToOpPassAdaptor::runPipeline (
599
600
OpPassManager &pm, Operation *op, AnalysisManager am, bool verifyPasses,
600
- unsigned parentInitGeneration, PassInstrumentor *instrumentor,
601
+ bool emitErrorOnFailure, unsigned parentInitGeneration,
602
+ PassInstrumentor *instrumentor,
601
603
const PassInstrumentation::PipelineParentInfo *parentInfo) {
602
604
assert ((!instrumentor || parentInfo) &&
603
605
" expected parent info if instrumentor is provided" );
@@ -616,8 +618,12 @@ LogicalResult OpToOpPassAdaptor::runPipeline(
616
618
}
617
619
618
620
for (Pass &pass : pm.getPasses ())
619
- if (failed (run (&pass, op, am, verifyPasses, parentInitGeneration)))
621
+ if (failed (run (&pass, op, am, verifyPasses, emitErrorOnFailure,
622
+ parentInitGeneration))) {
623
+ if (emitErrorOnFailure)
624
+ return op->emitError (" failed to run pass: " ) << pass.getName ();
620
625
return failure ();
626
+ }
621
627
622
628
if (instrumentor) {
623
629
instrumentor->runAfterPipeline (pm.getOpName (*op->getContext ()),
@@ -735,15 +741,17 @@ void OpToOpPassAdaptor::runOnOperation() {
735
741
}
736
742
737
743
// / Run the held pipeline over all nested operations.
738
- void OpToOpPassAdaptor::runOnOperation (bool verifyPasses) {
744
+ void OpToOpPassAdaptor::runOnOperation (bool verifyPasses,
745
+ bool emitErrorOnFailure) {
739
746
if (getContext ().isMultithreadingEnabled ())
740
- runOnOperationAsyncImpl (verifyPasses);
747
+ runOnOperationAsyncImpl (verifyPasses, emitErrorOnFailure );
741
748
else
742
- runOnOperationImpl (verifyPasses);
749
+ runOnOperationImpl (verifyPasses, emitErrorOnFailure );
743
750
}
744
751
745
752
// / Run this pass adaptor synchronously.
746
- void OpToOpPassAdaptor::runOnOperationImpl (bool verifyPasses) {
753
+ void OpToOpPassAdaptor::runOnOperationImpl (bool verifyPasses,
754
+ bool emitErrorOnFailure) {
747
755
auto am = getAnalysisManager ();
748
756
PassInstrumentation::PipelineParentInfo parentInfo = {llvm::get_threadid (),
749
757
this };
@@ -758,7 +766,8 @@ void OpToOpPassAdaptor::runOnOperationImpl(bool verifyPasses) {
758
766
// Run the held pipeline over the current operation.
759
767
unsigned initGeneration = mgr->impl ->initializationGeneration ;
760
768
if (failed (runPipeline (*mgr, &op, am.nest (&op), verifyPasses,
761
- initGeneration, instrumentor, &parentInfo)))
769
+ emitErrorOnFailure, initGeneration, instrumentor,
770
+ &parentInfo)))
762
771
signalPassFailure ();
763
772
}
764
773
}
@@ -775,7 +784,8 @@ static bool hasSizeMismatch(ArrayRef<OpPassManager> lhs,
775
784
}
776
785
777
786
// / Run this pass adaptor synchronously.
778
- void OpToOpPassAdaptor::runOnOperationAsyncImpl (bool verifyPasses) {
787
+ void OpToOpPassAdaptor::runOnOperationAsyncImpl (bool verifyPasses,
788
+ bool emitErrorOnFailure) {
779
789
AnalysisManager am = getAnalysisManager ();
780
790
MLIRContext *context = &getContext ();
781
791
@@ -838,7 +848,7 @@ void OpToOpPassAdaptor::runOnOperationAsyncImpl(bool verifyPasses) {
838
848
// Get the pass manager for this operation and execute it.
839
849
OpPassManager &pm = asyncExecutors[pmIndex][opInfo.passManagerIdx ];
840
850
LogicalResult pipelineResult = runPipeline (
841
- pm, opInfo.op , opInfo.am , verifyPasses,
851
+ pm, opInfo.op , opInfo.am , verifyPasses, emitErrorOnFailure,
842
852
pm.impl ->initializationGeneration , instrumentor, &parentInfo);
843
853
if (failed (pipelineResult))
844
854
hasFailure.store (true );
@@ -859,17 +869,21 @@ void OpToOpPassAdaptor::runOnOperationAsyncImpl(bool verifyPasses) {
859
869
PassManager::PassManager (MLIRContext *ctx, StringRef operationName,
860
870
Nesting nesting)
861
871
: OpPassManager(operationName, nesting), context(ctx), passTiming(false ),
862
- verifyPasses (true ) {}
872
+ verifyPasses (true ), emitErrorOnFailure( false ) {}
863
873
864
874
PassManager::PassManager (OperationName operationName, Nesting nesting)
865
875
: OpPassManager(operationName, nesting),
866
876
context(operationName.getContext()), passTiming(false ),
867
- verifyPasses(true ) {}
877
+ verifyPasses(true ), emitErrorOnFailure( false ) {}
868
878
869
879
PassManager::~PassManager () = default ;
870
880
871
881
void PassManager::enableVerifier (bool enabled) { verifyPasses = enabled; }
872
882
883
+ void PassManager::enableErrorOnFailure (bool enabled) {
884
+ emitErrorOnFailure = enabled;
885
+ }
886
+
873
887
// / Run the passes within this manager on the provided operation.
874
888
LogicalResult PassManager::run (Operation *op) {
875
889
MLIRContext *context = getContext ();
@@ -931,6 +945,7 @@ void PassManager::addInstrumentation(std::unique_ptr<PassInstrumentation> pi) {
931
945
932
946
LogicalResult PassManager::runPasses (Operation *op, AnalysisManager am) {
933
947
return OpToOpPassAdaptor::runPipeline (*this , op, am, verifyPasses,
948
+ emitErrorOnFailure,
934
949
impl->initializationGeneration );
935
950
}
936
951
0 commit comments